diff --git a/lib/nox-server.js b/lib/nox-server.js
index <HASH>..<HASH> 100644
--- a/lib/nox-server.js
+++ b/lib/nox-server.js
@@ -211,8 +211,6 @@ exports.nox = function(requirefun, cookiename, logfun, uglify) {
 
 	logfun('serving nox-client.js for ' + page.url + '\n');
 
-	res.writeHead(200, { 'Content-Type': 'text/javascript', 'Cache-Control': 'no-cache' });
-
 	var result = [];
 	async.waterfall([
 	    function(wfcb) {
@@ -323,13 +321,18 @@ exports.nox = function(requirefun, cookiename, logfun, uglify) {
 		wfcb();
 	    },
 	    function(wfcb) {
+		res.writeHead(200, { 'Content-Type': 'text/javascript', 
+				     'Cache-Control': 'no-cache' });
 		res.end(result);
 		wfcb();
 	    }
 	], function(err) {
-	    if( err )
+	    if( err ) {
+		res.writeHead(500);
+		res.end();
 		logfun('error creating ' + page.url + 
 		       '/nox-client.js:' + err + '\n');
+	    }
 	});
     }
give <I> response in error cases