From a66f901d9a39e9918f5366a459002a07df31c099 Mon Sep 17 00:00:00 2001 From: Astro Date: Tue, 21 Dec 2010 22:47:57 +0100 Subject: [PATCH] cache avoiding hacks --- quiz.js | 2 +- server.js | 11 ++++++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/quiz.js b/quiz.js index 63bd89c..6fcf444 100644 --- a/quiz.js +++ b/quiz.js @@ -32,7 +32,7 @@ var questions; var currentQuestion = 0; function loadQuizData(done) { - $.ajax({ url: 'data/questions.json', + $.ajax({ url: 'data/questions.json?' + Math.round(Math.random() * 1000), contentType: 'json', success: function(data, status) { if (typeof data === 'string') diff --git a/server.js b/server.js index 31d577b..e9d5516 100644 --- a/server.js +++ b/server.js @@ -87,11 +87,20 @@ function pushIrcInfo() { /* * Web server */ +function noCache(req, res, next) { + var writeHead = res.writeHead; + res.writeHead = function(status, headers) { + headers['Cache-Control'] = 'no-cache'; + writeHead.call(this, status, headers); + }; + next(); +} var server = Connect.createServer( Connect.logger(), + noCache, Connect.bodyDecoder(), - Connect.staticProvider(__dirname), + Connect.staticProvider({ root: __dirname, maxAge: 1000 }), Connect.errorHandler({ dumpExceptions: true, showStack: true }) );