-
-
Notifications
You must be signed in to change notification settings - Fork 26.9k
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
runtime~main.xxxx.js is inserted as inline script in generated index.html #5309
Comments
That’s intentional. We want to inline this chunk because it’s usually small and isn’t worth a separate request. But some people use asset manifest from CRA with a custom HTML so we want to make it easy for them to read it. |
For the record it is about 3Kb in my application (not sure if it is a lot or not). Update: also it can break in case of strict CSP |
It would still be a waste to send a separate HTTP request for a 3Kb file, unless you reload the page on every navigation (in which case you can add client-side routing?)
See #5288 |
Seems crazy to me to force the inline of a single script to save 1 request, and breaking the biggest win of CSP. Taken from Google's guide to CSP
As I see it, users of CRA implementing CSP will run their app, and likely see a console error similar to this This likely directs users down the path of least resistance (i.e the wrong path) by adding |
Yeah, this really doesn't seem to make sense. I don't want to have to add a weird build step where it tries to inject a nonce into the built
Isn't that was caching/HTTP2 is for? |
I hope it won't turn into battle as it was with ServiceWorkers. (This wasn't my intention when I opened issue) Also we can lock this ticket and continue conversation after #5288, which should address |
HTTP2 is very far from being widely adopted. Caching doesn’t help because the runtime chunk will be different on every build. That’s the exact reason why it exists — to separate it from less often changing code. I’m fine with adding an environment variable that disables the inlining. Wanna send a PR? |
That's great. I've never contributed to this project before, so I'll have a try at adding that now. Thanks! |
Probably look for |
https://caniuse.com/#search=http2 says only IE 11, Opera Mini and "UC Browser for Android" (whatever that is) does NOT support HTTP2. So for the majority of browsers, inline scripting small scripts makes the performance worse, ...in theory. I haven't done extensive measurements to support this but if the HTML document (the Also, leaving it on by default does encourage the risk of people letting their CSP policy include Having said all of that, I appreciate that I have a very limited context on the run-up to this change in 2.0 and perhaps I've missed some other subtle analysis of the advantages of inlining. What I'm suggesting is that it does not inline unless you set |
I'm guessing this was just a rough suggestion but let's at least denote that the inlining is based on some webpack rule that deems the script very small. |
Lastly about the web performance; inlining is often better than a blocking resource. I.e. it's better to serve a 700KB (than a 600KB) HTML document if it means you don't have to block the parsing until all Ideally, what you should do is |
If you have a specific proposal for how it should work (along with how to make webpack emit and work with
I was talking about what people use in production today, not about what they could possibly use based on browser support. Adoption depends on hosting, server side solutions and many other factors. Industry-wide, HTTP2 adoption is still low. |
Out in 2.0.5 |
Unless I'm mistaken, this doesn't appear to be resolved in 2.0.5; an inline script is still being added to
Am I mistaken in assuming this should not be happening anymore under 2.0.5? EDIT: It looks like there was some discussion in this issue and others about adding an environment variable. Is that what @gaearon was referring to with regards to it being "out in 2.0.5," or was that referring to something else? Apologies for the confusion. EDIT 2: Sorry, just saw #5354 and |
Is this a bug report?
Not sure. It seems like bug, but maybe there is a reason for this behaviour.
Did you try recovering your dependencies?
Yes
Which terms did you search for in User Guide?
None
Environment
Steps to Reproduce
yarn build
build/index.html
<script type="text/javascript">...
right below<div id="root" />
, which contains the same JS as inbuild/static/js/runtime~main.xxxx.js
Expected Behavior
I expect to see
<script src="static/js/runtime~main.xxxx.js">
instead of inline scriptActual Behavior
As I said it inlines
runtime~main.xxxx.js
for some reason.Reproducible Demo
react-scripts v2.0.4
The text was updated successfully, but these errors were encountered: