File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes HTML, CSS and JavaScript and the fly likes Javascript file loading Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "Javascript file loading" Watch "Javascript file loading" New topic

Javascript file loading

Pawanpreet Singh
Ranch Hand

Joined: Jun 12, 2005
Posts: 264

Hi All
We know that if we have included a js file in an html/jsp file, an on opening same url in different browser window, everytime js file is loaded along with page. But i want it to store in browser cache and i want that only one time, js should be loaded, and if same url is requested, its js should not be loaded with page and page use same old ones from browser cache.
Eric Pascarello

Joined: Nov 08, 2001
Posts: 15385
The external javascript files are designed to be cached by the browser. If they are not being cached, then it is most likely the browser settings are looking for a new version on every visit.

Yuriy Zilbergleyt
Ranch Hand

Joined: Dec 13, 2004
Posts: 429
Hmm, I know that if the browser is set to cache everything and only check for new content with a new browser instance, it is possible to set headers to make sure a page or a file is never cached (of course the browser has to recognize the headers, but it works with IE and Firefox). But is it possible to do the opposite - to force the browser to cache a resource even if the settings are "check for new content every visit to the page."

For example, if I have the same image displayed hundreds of times on a page, I don't care what the browser settings are - I don't want hundreds of requests for that image coming to my server from the same client.

I agree. Here's the link:
subject: Javascript file loading
It's not a secret anymore!