开发者

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 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


  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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜