Elliot B.
Elliot B.

Reputation: 17681

Browser caching when files are served from a network file-share

As I understand it, whether an item is cached by the web browser is determined by:

  1. What the response headers tell the browser to do (e.g., Cache-Control and Expires).
  2. The presence of a validator (e.g., ETag or Last-Modified header).

How does this differ for files served from a network file-share? Across different browsers? Consider this JavaScript include:

<script type="text/javascript" src="\\SOMECOMPUTER\folder\file.js"></script>

Will browsers obey a meta tag such as this one when network files are involved?

<META HTTP-EQUIV="EXPIRES" CONTENT="Mon, 31 Dec 2011 11:12:01 GMT">

I'm finding very little documentation on this topic.

Upvotes: 5

Views: 559

Answers (2)

gaborsch
gaborsch

Reputation: 15758

HTTP headers are only considered while the file is sent through HTTP protocol. The file access (both local and network share) are NOT going through HTTP, so you cannot control the cache with this.

HTML files has the cache control in the <head> section with meta tags. So, if you want to control the cache for the .html file, you can do it. The above is unfortunately not true for .js files, you cannot control the js file caching this way.

I would recommend 2 options:

  • Set up a small HTTP server, and fetch the .js files from there - this way you van control the cache timeout by HTTP headers
  • Inline your JavaScript code into a HTML page (in <script>...</script> tags), and control the caching by <meta> tags. This way you can load this file in a <div src="\\server\cachedfile.html" \> - the div could be even hidden after loading.

I think that the second option is better, because the <meta> cache control is more reliable and even more controllable.

Upvotes: 1

Andrew Hagner
Andrew Hagner

Reputation: 804

Edit: After actually doing some more tests, you can access the file that way with IE8, Firefox, and Google, assuming the proper permissions are setup, sorry for prior confusion.

Now its just back to the matter of will it cache java-script files (or any really), which is yes. So here's how you could fix that:

Using <meta> tags to turn off caching in all browsers? (This seemed to work fine for me so it appears that the browsers will listen to the meta tags for network files like this)

How to force IE to reload javascript? (This works just like how you would avoid caching ajax calls by appending the time to it as an unused variable)

Upvotes: 4

Related Questions