How to store a javascript widget which has analytics? Dynamic or static?
I have a widget for which I provide a boot开发者_运维技巧 loader to put on the website. The bootloader file gets the settings for the widget and creates the widget. The content of this bootloader file doesn't change much often unless the widget is edited, which means that the most of the times the bootloader file has static content.
However right now the bootloader file is created dynamically with every request. I save the settings for the widget in a database and then serve the file. THe size of this file is about 6KB. I was wondering what would be better: to save the data in a database and serve the bootloader file dynamically, to save the data in a static javascript file or to store the data in a database and also store the data in a javascript file (this allows for later updates in corrupted javascript files)
Also, I wondered if I stored the static js file as .js.gz (compressed) and .js(uncompressed) then how would I serve the uncompressed file when the browser does not support the compressed file...Could the same be done if dynamic bootloader file is used.
The bootloader file is used to get the json content which is processed by the bootloader file and displayed, so this means that bootloader file is better if cached to prevent getting the js over and over again.
So
->How should the file be stored?
->How much difference in speed?
->Any other advice?
I think you would be better of storing the file as javascript and then keeping a copy of it in the database for backup purposes. serving a a static javascript can be as much as 10 times faster....Also, this would mean that your cpu would be working less hard.
精彩评论