-
Notifications
You must be signed in to change notification settings - Fork 333
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cache bust #1350
Cache bust #1350
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey, so sorry - this dropped off my radar somehow and I forgot about it :(
I started going through and leaving comments but stopped since I'm not sure this is the best approach - AFAICT this compiles templates each startup and caches them in memory, right? I'm not sure this is better than having a build step that writes templates back to disk, similar to what we currently have. That makes startup faster and it improves memory usage.
I'm not really sure, honestly.
lib/template.js
Outdated
// | ||
// Template middleware with cache-buster | ||
// | ||
// Copyright 2012, E14N https://e14n.com/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be adjusted :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
made
lib/template.js
Outdated
var fs = require("fs"), | ||
path = require("path"), | ||
crypto = require("crypto"), | ||
_ = require("underscore"), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this was submitted we've migrated to Lodash so this needs to be adjusted. Sorry, that's my bad :(
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
made
lib/template.js
Outdated
"// \n" + | ||
"// @licend The above is the entire license notice\n" + | ||
"// for the JavaScript code in this page.\n\n" + | ||
"// XXX: this needs to be broken up into 3-4 smaller modules \n"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This probably doesn't belong here?
lib/template.js
Outdated
"// @licstart The following is the entire license notice for the \n" + | ||
"// JavaScript code in this page.\n" + | ||
"// \n" + | ||
"// Copyright 2011-2013, E14N https://e14n.com/\n" + |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should probably read:
Copyright 2011-2017, E14N https://e14n.com/ and contributors
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
made
lib/template.js
Outdated
"// XXX: this needs to be broken up into 3-4 smaller modules \n"; | ||
|
||
|
||
// Get al files from views directory but only take all .jade files |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
all
instead of al
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
made
lib/template.js
Outdated
templateContent = fs.readFileSync(templatePath, {encoding: "utf8"}), | ||
// Compile jade template for client side | ||
templateFn = jade.compileClient(templateContent, { | ||
externalRuntime: false, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is this option? I don't see it in the docs; maybe you meant inlineRuntimeFunctions
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In jade 1.11.x both optionsexternalRuntime
or inlineRuntimeFunctions
not exist, see: https://github.com/pugjs/pug/tree/master/packages/pug-runtime pugjs/pug@1eeb9e6
Memory is always faster than read from disk (example swap vs zswap), reduce IO-Operations is always better for performance, this option is also more friendly for frontend developers and don't increment much the startup time only increment seconds more https://www.backblaze.com/blog/whats-diff-ram-vs-storage/ |
Changes Unknown when pulling 0cdf6ec on vxcamiloxv:cache-bust into ** on pump-io:master**. |
2 similar comments
2 similar comments
2 similar comments
This middleware returns a jade template compile function minified or not with unique hash by template, the client side get a template hash from a list where live availables templates, aditional set a max-age expiration for better render performance in client-side and is more friendly with development because not need build templates manually. Related: #1204
'inlineRuntimeFunctions' option not exist in jade 1.x, Added for compatibility in future 'pug' upgrades
@strugee I was thinking about other ways to make better this implementation and if you still thinking keep in memory could be have performance issues I have two options. Server side optionsA) The B) I'll modified the request path and remove the hash, Will delegate the response to Client side options.A) Reads all statics files and make hash, keeps in memory (only name file and hash)
B) A build task (a
script(src=getFileHash("/javascript/dist/pump.min.js")) and the results <script src="/javascript/dist/pump.min.hdg6252.js"></script> Generation optionsA) Generate and minified all statics in for example B) Generate, minified and saves all statics by server on startup (developer friendly) What do you think? |
I close this PR because has 9 months, and I was thinking in a better and more generic approach for that (not only templates), I Will work over options the previous comment. |
Template middleware return a jade compile function
minified or not with unique hash by template, the client side
get a template hash from a list where live availables templates,
aditional set a max-age expiration for better render performance
in client-side and is more friendly with development because not
need build templates manually.
Closes: #1204