Skip to content
Browse files

cache static assets

  • Loading branch information...
1 parent 9d91166 commit 9bf30741a4250efc2f2bb156e36fae4812d084ff @dantebronto committed Jan 29, 2011
Showing with 15 additions and 6 deletions.
  1. +15 −6 lib/picard/template.js
View
21 lib/picard/template.js
@@ -101,16 +101,25 @@ var Template = {
serveStatic: function(req, file){
var name = req.parsedUrl().pathname,
filename = file || this.root + this.public + name
+
+ if ( typeof Template.cache[filename] == 'undefined' || this.mode == 'development' ) {
+ fs.readFile(filename, 'binary', function(err, content){
+ if ( err ) req.onScreen(null)
+ Template.cache[filename] = content
- fs.readFile(filename, 'binary', function(err, content){
- if ( err ) req.onScreen(null)
-
- req.onScreen({
- body: content,
+ req.onScreen({
+ body: content || null,
+ type: mime.lookupExtension(filename.match(/.[^.]*$/)[0]),
+ encoding: 'binary'
+ })
+ })
+ } else {
+ req.onScreen({
+ body: Template.cache[filename] || null,
type: mime.lookupExtension(filename.match(/.[^.]*$/)[0]),
encoding: 'binary'
})
- })
+ }
}
}

0 comments on commit 9bf3074

Please sign in to comment.
Something went wrong with that request. Please try again.