-
-
Notifications
You must be signed in to change notification settings - Fork 384
Some small optimizations for stylesheet injection #328
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -353,7 +353,6 @@ class MiniCssExtractPlugin { | |
'}', | ||
'var linkTag = document.createElement("link");', | ||
'linkTag.rel = "stylesheet";', | ||
'linkTag.type = "text/css";', | ||
'linkTag.onload = resolve;', | ||
'linkTag.onerror = function(event) {', | ||
Template.indent([ | ||
|
@@ -368,7 +367,7 @@ class MiniCssExtractPlugin { | |
'linkTag.href = fullhref;', | ||
crossOriginLoading | ||
? Template.asString([ | ||
`if (linkTag.href.indexOf(window.location.origin + '/') !== 0) {`, | ||
`if (linkTag.href.indexOf(location.origin + '/') !== 0) {`, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Always need There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. agreed, don't rely on global scope being there. explicit, no implicit is always my suggestion There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What scope problem are you referring to?
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note that the code already uses There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fair point... we should side with implicit or explicit conventions throughout There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I’ve had scope issues before. Rarely but they do happen. Even if wasted bytes. This plugin gets like 5mil downloads a week. Eventually complaints would roll in. We are talking race conditions. Stupid question, what if we declared window as a variable, then w.document or w.location? One way to save bytes maybe. Can’t speak if race conditions would come of this never tried There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I don't see a race condition here.
If gzip's involved, that uses more bytes than Fwiw I think omitting |
||
Template.indent( | ||
`linkTag.crossOrigin = ${JSON.stringify( | ||
crossOriginLoading | ||
|
@@ -377,8 +376,7 @@ class MiniCssExtractPlugin { | |
'}', | ||
]) | ||
: '', | ||
'var head = document.getElementsByTagName("head")[0];', | ||
'head.appendChild(linkTag);', | ||
'document.head.appendChild(linkTag);', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hm IE9 doesn't support There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @evilebottnawi looks safe to me? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @ScriptedAlchemy for me too, so i asked question why it was changed There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah good point. Though both of them do work with old I.E. However I’m unsure how widely supported ‘document.head’ is especially in older browsers There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks like Webpack core has also switched over to using |
||
]), | ||
'}).then(function() {', | ||
Template.indent(['installedCssChunks[chunkId] = 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.
Why we need remove this? Not sure it is right idea
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.
Removing
text/css
good for HTML5, but some browsers (include mobile) still have bad supporting HTML5There 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.
Keep compatibility as long as we can. Third-world countries and the corporations there can and usually are locked on older "legacy” devices or browsers
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.
The default value of the
type
attribute has always beentext/css
. The only difference in HTML5 was making it pass validation when omitted. There is no functionality change with regard to this behaviour between the two specs.You can test this yourself - load this webpage in IE6:
(also worth noting: an argument for specifying
type
on<link>
tags implies we should do the same for<script>
, which is universally regarded as unnecessary)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.
Nicely done