-
Notifications
You must be signed in to change notification settings - Fork 10
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
enhancement/issue 629 cache unchanged assets in development #760
enhancement/issue 629 cache unchanged assets in development #760
Conversation
if (inm && inm === etagHash) { | ||
ctx.status = 304; | ||
ctx.body = null; | ||
ctx.set('Etag', etagHash); |
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.
Not sure if there's a reason to not ever to set the ETag
, or what the implications of setting it all the time would be? 🤔
@@ -285,7 +285,9 @@ class NodeModulesResource extends ResourceInterface { | |||
// for each entry found in dependencies, find its entry point | |||
// then walk its entry point (e.g. index.js) for imports / exports to add to the importMap | |||
// and then walk its package.json for transitive dependencies and all those import / exports | |||
walkPackageJson(userPackageJson); | |||
if (Object.keys(importMap).length === 0) { |
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.
not sure if there is something more elegant other than initializing importMap = null
, but effectively walking no dependencies should be almost zero cost as it is? Ideally for someone with a handful of dependencies, walking that everytime would be annoying.
Another thought, if we only need to do this once, then in theory we should also be able to include this in the should intercept logic instead?
async shouldIntercept(url, body, headers) {
return Promise.resolve(Object.keys(importMap).length === 0 && headers.response['content-type'] === 'text/html');
}
0418b18
to
43c2d75
Compare
BenchmarkingSo did some local testing with Chrome and Firefox on master vs this branch. Results are basically almost a 50% percent improvement for refreshed and live reloads, which is pretty awesome! With E-Tags, unchanged assets stay the same naturally, which you can by their E-Tag staying the same, which adds a really nice level of granularity to loading. 💪 It should be noted Firefox is pretty fast overall, compared to Chrome but everything feels a lot quicker and responsive now overall. ✨ 💯 MasterFirefoxChromeCurrent BranchFirefoxChrome |
43c2d75
to
bfce7ce
Compare
0bd2e3c
to
1ee4f54
Compare
Related Issue
resolves #629 and #553
Summary of Changes
importMap
from initial walking of all dependenciesETag
andIf-None-Match
headers respectively as part of dev server request / response middleware. Also settingCache-Control
header too.hashString
functionBenchmarks - #760 (comment)
TODOs
Cache-Control
hashString
implementationTesting / Demo
So far this works great in Firefox, but testing (as in this feature) can be thought of as a stepping stone to HMR. The value here is in seeing if development is / feels faster with these changes as opposed to not having it.
develop
command and observe the status of everything should be200
304
200
and the page should have changed, but everything else stays304
304
for everythingQuestions
null
check onctx.body
. Maybe it's something we could apply toResourceInterface
?