I'm having trouble with the HTML5 AppCache and the requests that it sends, so I wrote a small demonstration of the problem. First, there are two HTML files. One is called withmanifest.html
, and looks like this:
<html manifest="hello.appcache">
<body>
Hello world
<script src="client.js"></script>
</body>
</html>
The second HTML file is called withoutmanifest.html
, and is completely identical except it omits the manifest attribute. The client.js
file is just a single line - it doesn't do anything interesting. The hello.appcache
file caches client.js
.
I created a simple node.js server (server.js
) to serve static files in the directory and log the URL and referer header for every request:
http = require('http');
nodeStatic = require('node-static');
var staticFileServer = new nodeStatic.Server('./', {cache: 0});
http.createServer(function(req, res) {
console.log(req.url + ' ' + (req.headers['referer'] || 'None'));
req.addListener('end', function() {
staticFileServer.serve(req, res);
}).resume();
}).listen(8000);
The full code (~50 lines total) is available on github.
In Chrome, with no AppCaches set (chrome://appcache-internals is empty), I load /withoutmanifest.html
and get the following log:
/withoutmanifest.html None
/client.js http://localhost:8000/withoutmanifest.html
/favicon.ico None
I then load /withmanifest.html
and get the following log:
/withmanifest.html None
/hello.appcache None
/client.js http://localhost:8000/withoutmanifest.html
/client.js None
/withmanifest.html None
/hello.appcache None
The second request for client.js
is sent by the AppCache update process and does not contain a referer header. This is a problem, because what I'm really trying to do is query another server, and that server returns an error if the request doesn't have a referer. I'm not sure what to do next - it seems very strange to me that the AppCache would send a different request from the page itself. Is there any way to set the referer header?