From 7bbfc37df6217233725b024473e05a794f555a77 Mon Sep 17 00:00:00 2001 From: Terin Stock Date: Fri, 22 Apr 2016 11:26:28 -0700 Subject: [PATCH] automatically insert Link rel="preload" headers --- core/server/config/index.js | 3 ++- core/server/middleware/index.js | 9 +++++++++ package.json | 1 + 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/core/server/config/index.js b/core/server/config/index.js index 2ca4561632..4fa4da9703 100644 --- a/core/server/config/index.js +++ b/core/server/config/index.js @@ -212,7 +212,8 @@ ConfigManager.prototype.set = function (config) { }, deprecatedItems: ['updateCheck', 'mail.fromaddress'], // create a hash for cache busting assets - assetHash: assetHash + assetHash: assetHash, + preloadHeaders: this._config.preloadHeaders || false }); // Also pass config object to diff --git a/core/server/middleware/index.js b/core/server/middleware/index.js index d8d3971b1e..0d5435f054 100644 --- a/core/server/middleware/index.js +++ b/core/server/middleware/index.js @@ -25,6 +25,7 @@ var bodyParser = require('body-parser'), themeHandler = require('./theme-handler'), uncapitalise = require('./uncapitalise'), cors = require('./cors'), + netjet = require('netjet'), ClientPasswordStrategy = require('passport-oauth2-client-password').Strategy, BearerStrategy = require('passport-http-bearer').Strategy, @@ -70,6 +71,14 @@ setupMiddleware = function setupMiddleware(blogApp, adminApp) { } } + // Preload link headers + if (config.preloadHeaders) { + blogApp.use(netjet({ + cache: { + max: config.preloadHeaders + } + })); + } // Favicon blogApp.use(serveSharedFile('favicon.ico', 'image/x-icon', utils.ONE_DAY_S)); diff --git a/package.json b/package.json index 393d5e96ef..40c46fa207 100644 --- a/package.json +++ b/package.json @@ -53,6 +53,7 @@ "moment": "2.13.0", "morgan": "1.7.0", "multer": "1.1.0", + "netjet": "1.1.0", "node-uuid": "1.4.7", "nodemailer": "0.7.1", "oauth2orize": "1.2.2",