0

Possible Duplicate:
caching JavaScript files

I'm using JQuery 1.7.2 into JSF page. I call several times jquery-1.7.2.min.js into the body of the page. In general is it possible to configure the web browser to download the library only once and use it instead of downloading it every time?

Community
  • 1
  • 1
user1285928
  • 1,328
  • 29
  • 98
  • 147

2 Answers2

2

If you always load it from the same kind of URL (domain etc..) then it'll be cached by your browser anyway. This is way CDNs are so useful as more sites will use them s.t. if the user comes to your page he might already have jQuery cached in his browser (due to visiting some other page before)

Juri
  • 32,424
  • 20
  • 102
  • 136
2

Use localStorage then when the page loads check if jQuery is stored in local cache if not then create ajax request save to localStorage and append into script header.

If client again visit page just load from localstorage into html + failback load jQuery standard

But need use pure JavaScript code


Code:

Download jQuery only one time per few years:

https://gist.github.com/3844878

Jason Aller
  • 3,541
  • 28
  • 38
  • 38
user956584
  • 5,316
  • 3
  • 40
  • 50
  • 1
    What do you suggest putting into local storage, the entire jQuery library or the script in the page that's calling jQuery? The OP didn't mention anything about needing offline functionality, so local storage seems like overkill IMO for his/her needs. – PHeiberg Oct 06 '12 at 12:32
  • Sorry this is unexpected feature ;) – user956584 Oct 06 '12 at 13:05
  • LocalStorage is not made for caching JavaScript files, but for providing offline functionality. – Juri Oct 06 '12 at 15:23
  • But is working, off-line functionality show annoying warning and implementation offline - online is wasting time for small application – user956584 Oct 06 '12 at 15:32