I am working for an intranet application. Therefore I have some control on the client machines. The JavaScript library I am using is somewhat big in size. I would like to pre-install OR pre-load OR cache the JavaScript library on each machine (each browser as well) so that it does not travel for each request. I know that browsers do cache a JavaScript library for subsequent requests but I would like the library to be cached once for all subsequent requests, sessions and users.
What is the best mechanism to achieve this?
You don’t need access to the client machines for this. Best practices are all serverside:
The last two points mean the content is cached until it changes. You can use an actual version number for official releases (eg jquery-1.4.2.min.js, the 1.4.2 is a version number). For code for your own application, often you’ll use something like the mtime (last modified time) of the file as a query string. For example:
After the
?is generated from the modified time of the file. The client downloads it once and because of the far futureExpiresheader it won’t be downloaded again until the version number changes, which won’t happen until the file changes.