diff --git a/webServer.js b/webServer.js index 5c22e28213..0f5feef7d9 100755 --- a/webServer.js +++ b/webServer.js @@ -113,8 +113,44 @@ function start() { res.setHeader("Expires", new Date(Date.now() + 60 * 60 * hours * 1000).toUTCString()); } + var serverPush = function(res, uri) { + var temp = uri.split('.'), ext = temp[temp.length-1], as = -1; + switch (ext) { + case 'js': + as='script'; + break; + case 'css': + as='style'; + break; + case 'png' : + case 'jpg' : + case 'jpeg': + case 'gif' : + case 'ico' : + as='image'; + break; + case 'xml' : + as=''; + break; + } + delete temp; + if (as != -1) { + res.setHeader("Link", "<" + uri + ">; rel=preload; as=" + as "); + } + delete temp; + delete ext; + delete as; + } + + function pushAssets(res) { + serverPush(res, '/css/theme.css'); + serverPush(res, '/css/main.css'); + serverPush(res, '/js/main.js'); + } app.get('/', function(req, res) { + pushAssets(res); + serverPush(res, '/img/algolia64x20.png'); setCache(res, 2); res.send(generatePage({ page: { @@ -379,7 +415,6 @@ function start() { app.get('/gitstats', function(req, res) { return res.redirect(301, '/gitstats/cdnjs'); }); app.get('/git_stats', function(req, res) { return res.redirect(301, '/git_stats/cdnjs'); }); app.get('/about', function(req, res) { - setCache(res, 72); res.send(generatePage({ page: {