If I am using a large Javascript library for my page, how can I make sure that this does not impair the user's use of the site?
|
There are 4 things you can do.
And some other people have suggested:
|
||||
|
|
If you are using common libraries (such as jQuery, Prototype or Dojo), you can offload the file to Google and make them serve it, this gives you several advantages:
Note: The version you ask for can have a large impact on the caching characteristics: asking for jQuery 1.4.2 will give you a file that can be cached for a year, but 1.4 can only be cached for an hour. |
|||||||||||||||
|
|
You can put the whole library into one js file and compress the file. However, it really only matters for the first loading of a page. After this your js file will be cached in the browser, in particular if you set the cache-expiration long enough. Hence any consecutive hit will not load your js file anymore. |
|||
|
|
In addition to the answers above, you can use the Google Closure Compiler to automatically compress and optimize your JS while integrating with other 3rd party libraries (jQuery, YUI, mootools, etc.) |
|||
|
|
|
If you have a number of page elements & access to separate domain, you can consider hosting all static files including the large JS file on the second domain. As Steve Souders notes in his High Performance Web Sites blog -
elsewhere he writes..
|
|||
|
|