From bc1c419722d82e5fe00fa9930b6feea0e0160910 Mon Sep 17 00:00:00 2001 From: Julian Lam Date: Tue, 25 Feb 2014 15:20:21 -0500 Subject: [PATCH] caching compiled CSS locally, so repeated calls to the stylesheet serve from cache --- src/meta.js | 4 ++++ src/routes/theme.js | 9 +++++++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/meta.js b/src/meta.js index 419f293648..e494c4fccc 100644 --- a/src/meta.js +++ b/src/meta.js @@ -337,6 +337,10 @@ var fs = require('fs'), } }; + Meta.css = { + cache: undefined + }; + Meta.restart = function() { if (process.send) { process.send('nodebb:restart'); diff --git a/src/routes/theme.js b/src/routes/theme.js index f4e260352f..e8a9052029 100644 --- a/src/routes/theme.js +++ b/src/routes/theme.js @@ -9,6 +9,11 @@ var path = require('path'), (function (Meta) { Meta.createRoutes = function(app) { app.get('/stylesheet.css', function(req, res) { + if (meta.css.cache) { + res.type('text/css').send(200, meta.css.cache); + return; + } + db.getObjectFields('config', ['theme:type', 'theme:id'], function(err, themeData) { var themeId = (themeData['theme:id'] || 'nodebb-theme-vanilla'), baseThemePath = path.join(nconf.get('themes_path'), themeId), @@ -31,11 +36,11 @@ var path = require('path'), parser.parse(source, function(err, tree) { if (err) { res.send(500, err.message); - console.log(err); return; } - res.type('text/css').send(200, tree.toCSS()); + meta.css.cache = tree.toCSS(); + res.type('text/css').send(200, meta.css.cache); }); } else { // Bootswatch theme not supported yet