简体   繁体   中英

jquery/javascript caching question

i was wondering - when using jQuery (or any other javascript include) in my web, does the browser cache it after the first download for all all pages (i assume yes) or will it download it every time?

2nd, when the user quits the browser and starts it again (for loading my website), will the jquery js file still be cached or will it completely download again?

thx

This depends on the browser and on how your server is set up. Have a look at the headers sent by the server along with the file (you can use a tool like Firebug to look at the headers). A good idea is to use the jQuery file hosted by google, since many other sites (including stackoverflow) use the same file. Then the browser can cache that file and never download it from your server. This page has a list of files hosted by google, and this page explains how to properly set your server up to (tell your browser to) cache files.

  1. Yes the scripts will get cached between page views, along with the CSS files and images.

  2. Yes as well, in general. The cache is normally maintained between browser restarts.

1: Yes, the browser caches all jscript/css includes

2: If the user does not clear his/her cache. Yes it will still be in the cache of the browser, even after closing and reopening it.

If your webserver serves jquery.js using a proper expires header, then yes, the browser will cache it.

http://developer.yahoo.com/performance/rules.html#expires

It will typically not be downloaded again, but unless your server explicitly tells the browser to cache it for a while, then it will send a request on each page load asking "was jquery.js updated?" which is almost as slow as just downloading it again.

You can test how it works on your site with Google's Page Speed or Yahoo's YSlow .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM