I am creating a google chrome extension to help with testing. The extension basically fills and input with dummy data.
I ne开发者_运维知识库ed to store this dummy data somehow.
The dummy data will not change, so hard coding it is acceptable.
What would the best way to do this be?
(think 2000 Male First Names, 2000 Female First Names, 4000 Last Names, 5000 Company Names, 5000 email addresses, 50 country names, all cities in those countries, localized phone formats for all 50 countries etc.)
as you can see it is quite a substantial amount of data.
My extension already requests unlimited storage.
Should I use A web db? or an whole pile of arrays? or maybe an object containing arrays?
Storing it in an array is not a bad idea. You can create a separated data.js
file that contains all the array initializations and then just include it into a background page as a usual script.
Other possibility would be localStorage (but you need to initialize it somehow, which means probably reading from an array and saving to a storage, which makes localStorage kind of useless extra step). localStorage is more useful when you want to preserve user created data between extension upgrades.
WebDB would be an overkill here I think, plus you still need to initialize it somehow, which again means reading from an array. The only advantage is that you would be able to run data queries, but js implementation in Chrome has lots of array manipulation methods so you can emulate queries on arrays too.
I think in your case if all the data is defined upfront and never changes arrays would be the best solution.
For Google Chrome Extension, you should be using Web SQL Database or IndexDB. You can find the difference here: http://hacks.mozilla.org/2010/06/comparing-indexeddb-and-webdatabase/
精彩评论