Skip to content
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

is it possible to stop browser to refetch scripts and reevaluate them if they haven't changed? #978

Closed
jasan-s opened this issue Sep 14, 2016 · 2 comments

Comments

@jasan-s
Copy link

jasan-s commented Sep 14, 2016

I'm currently using service worker (using sw-precache) to cache my React app vendor.js(2.14MB) and app.js(212kb) scripts along with some other assets. however, on page reload all my assets are fetched again and the response 200 comes from service worker (cache), but all scripts are complied and reevaluated. So the app shell disappears for a little over a second and reappears. IS is possible to stop browser from fetching the vendor script or the app script if it hasn't changed and evaluating it again ? my service worker script does run first before vendor.js and app.js so I can check if my cached resources have changed? That way the on reload the appshell renders near instantly.

@jakearchibald
Copy link
Contributor

I'm going to close this because it doesn't seem like a service worker spec issue, but I'll continue to provide support (and reopen it if it does turn out to be a spec issue).

I'm currently using service worker (using sw-precache) to cache my React app vendor.js(2.14MB) and app.js(212kb)

That's a huge amount of JavaScript, likely to bring a lower-end device to a crawl. Do you really need all that? For instance, the entire SVGOMG app is 100k, and achieves its first UI render in less than 5k.

I don't know your app, so maybe it does need that amount of code, but does it need all that code up front? I had a little rant about this on Twitter https://twitter.com/jaffathecake/status/776015862914514944.

So the app shell disappears for a little over a second and reappears

The key is to render before & without your JavaScript.

IS is possible to stop browser from fetching the vendor script or the app script if it hasn't changed and evaluating it again ?

But if that script is rendering the page, won't you be left with a blank page? You could cache the output of the script, but if this is acceptable, why not do that on the server or as part of a build process?

@wanderview
Copy link
Member

wanderview commented Sep 14, 2016

Yea, I think js engine compilation caching or serving pre-compiled js is orthogonal to service workers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants