For example let us say that we want to save a list of URLs and this list is updated dynamically. The following are the ways that I see this can be done.
1) Save in a text file
2) Save in a SQLite data base
3) Save in a preference (I know preferences are for storing preferences but is there any drawback of using a preference?)
What is the best method to save data related to a Firefox add-on? If a generic answer is not possible, what is the best method for a situation like the example above? And why do you think that such a method is appropriate and others are not?
Right-clickHold down the Ctrl key while you click on your profile folder (e.g. xxxxxxxx. default), and select Copy. Right-clickHold down the Ctrl key while you click the backup location (e.g. a USB-stick or a blank CD-RW disc), and select Paste .
Extension MetadataTell websites that you prefer to save data and costs. At websites' discretion, you may see lower quality images and fewer media elements as webpages adjust to reduce data downloads. The extension works by sending the Save-Data: on HTTP header with every request.
Preferences are simple and lightweight, but your storage requirements could outgrow preferences. SQLite is good for larger sets of data that need fast query capabilities. I find using file-based storage simple and effective. Just make sure you use async I/O whenever possible.
Saving the data to a JSON (or other format) text file is a simple thing to do. The Firefox session store does the same thing. When saving, use the profile folder location, maybe even make a sub folder.
MDN has notes on finding the profile folder and reading/writing a text file:
You can use the nsIJSON
component in older releases or the built-in JSON object in current releases of Firefox: https://developer.mozilla.org/en/JSON
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With