Permalink
Browse files

AC: Use fingerprint grunt task to only update asset cache when files …

…are changed, not on every page load.
  • Loading branch information...
1 parent 3ae3342 commit 1d2a1fbb1f3830f2eb5c7ec835fa82bf7714d00e @andrewchilds andrewchilds committed Feb 18, 2013
Showing with 21 additions and 2 deletions.
  1. +1 −0 .gitignore
  2. +7 −1 app/modules/routes.js
  3. +12 −1 grunt.js
  4. +1 −0 package.json
View
1 .gitignore
@@ -1,4 +1,5 @@
.DS_Store
+fingerprint
node_modules
app/public/css/bundle/*
app/public/js/bundle/*
View
8 app/modules/routes.js
@@ -1,10 +1,16 @@
+var fs = require('fs');
var pivotal = require('pivotal');
var TWO_YEARS = 2 * 365 * 24 * 60 * 60 * 1000;
var PIVOTAL_TOKEN_COOKIE = 'pivotalToken';
exports.index = function (req, res) {
- res.render('index', { timestamp: new Date().getTime() });
+ fs.readFile('./fingerprint', function (err, data) {
+ if (err) {
+ console.log('Fingerprint file not found, using current timestamp instead.');
+ }
+ res.render('index', { timestamp: data || new Date().getTime() });
+ });
};
exports.hasToken = function (req, res, next) {
View
13 grunt.js
@@ -17,6 +17,15 @@ module.exports = function(grunt) {
'app/public/js/lib/hogan.js'
]
},
+ fingerprint: {
+ assets: {
+ files: [
+ 'app/public/js/bundle/*',
+ 'app/public/css/bundle/*'
+ ],
+ filename: 'fingerprint'
+ }
+ },
hogan: {
compile: {
namespace: 'HoganTemplates',
@@ -84,7 +93,9 @@ module.exports = function(grunt) {
grunt.file.write(data.dest, output);
});
+ grunt.loadNpmTasks('grunt-fingerprint');
+
// Default task.
- grunt.registerTask('default', 'lint hogan concat min');
+ grunt.registerTask('default', 'lint hogan concat min fingerprint');
};
View
1 package.json
@@ -10,6 +10,7 @@
"hogan.js": "*",
"jade": "*",
"jira": "git://github.com/intentmedia/node-jira.git#master",
+ "grunt-fingerprint": "*",
"pivotal": "git://github.com/Wizcorp/node-pivotal.git#master",
"redis": "*",
"request": "*"

0 comments on commit 1d2a1fb

Please sign in to comment.