5
votes

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.

2
This doesnt answer your question, but were it me i would try to avoid linking like this and instead make sure the web server has access to the share via a path on the server for example http://intranet/files might actually be z:\SomeShare which is a network drive mapped to \\SomeComputer\filesprodigitalson
Unfortunately avoiding the file-share deployment isn't an option for us. We're deploying a JS heavy web app into intranets with IT department mandates on where we can put things. Sometimes an intranet web server is available, but more often it's not.Elliot B.
HTTP controls the cache - by not using a web server everything HTTP does for you goes out the window.Diodeus - James MacFarlane
I don't think the browser lets you access shared files like that. It only works when you test the html files from your hard drive because most security aspects are disabled.Stefanos Kalantzis
I tested with a simple html file and chrome silently hid the request, while FF tried to access it via http (and of course it didn't exist).Stefanos Kalantzis

2 Answers

1
votes

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.

4
votes

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)