Skip to content

Commit

Permalink
Merge pull request #398 from andreban/critical-res-push
Browse files Browse the repository at this point in the history
Adds Link header to preload critical resources
  • Loading branch information
juliantoledo authored May 9, 2017
2 parents e1cc744 + 60d2957 commit e411f6c
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions middlewares/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@
*/

const express = require('express');
const asset = require('../lib/asset-hashing').asset;
const router = express.Router(); // eslint-disable-line new-cap
const CSSPATH = asset.encode('/css/style.css');
const JSPATH = asset.encode('/js/gulliver.js');

router.use((req, res, next) => {
res.setHeader('Content-Type', 'text/html');
Expand All @@ -34,6 +37,12 @@ router.use((req, res, next) => {
res.setHeader('x-download-options', 'noopen');
res.setHeader('x-frame-options', 'SAMEORIGIN');
res.setHeader('x-xss-protection', '1; mode=block');

// Set the preload header if a full render is being requested.
if (!req.query.contentOnly) {
res.setHeader('Link',
`<${CSSPATH}>; rel=preload; as=style, <${JSPATH}>; rel=preload; as=script`);
}
next();
});

Expand Down

0 comments on commit e411f6c

Please sign in to comment.