Comments (10)
Looking at the code (briefly-ish), it seems like setting media to "print" would work.
from loadcss.
I think this change seems fine - loadCSS can function the same way using a valid non-matching query like print
, which may be what I would use. That said, a lot of sites use loadCSS (or more generally, the media toggle approach) and I'm not sure how likely it is that they'll update. In those cases, you might cause a bunch of sites to break and lose their css layout. What's a good tool for checking that?
from loadcss.
That ("print" working) is good news per se. 😃
Unconventional idea: what if we hardcoded Chrome’s loading algorithm to consider "only x" still load-worthy?
from loadcss.
Could I ask, what's the issue leading up to this change? I could see this saving a few requests on some sites, but is it more than that?
from loadcss.
Unconventional idea: what if we hardcoded Chrome’s loading algorithm to consider "only x" still load-worthy?
I doubt that would fly. I'm also not sure that loadCSS is the only user-space library doing this.
from loadcss.
I am sure it isn't. This pattern alone is pretty common, without a JS lib:
<link rel="stylesheet" media="foo" href="styles.css" onload="this.media='all'">
The drawbacks with that are now pretty far in the past, with link[onload] working more broadly.
The onload handlers might be worth searching for, since they might vary less than media usage. There are probably a bunch that set to this.media=screen
onload too, though.
from loadcss.
Noted in the other thread, AMP uses a different value for this pattern, also an invalid mq. https://github.com/ampproject/amphtml/blob/878909e3fa568ff2dceea4589579b76e6b624930/src/font-stylesheet-timeout.js#L89-L92
from loadcss.
Noted in the other thread, AMP uses a different value for this pattern, also an invalid mq. https://github.com/ampproject/amphtml/blob/878909e3fa568ff2dceea4589579b76e6b624930/src/font-stylesheet-timeout.js#L89-L92
Tracked in ampproject/amphtml#22984.
from loadcss.
Could I ask, what's the issue leading up to this change? I could see this saving a few requests on some sites, but is it more than that?
This came up in the context of CSS loading strategies for dark mode (non-publicized staging link, please don’t share).
from loadcss.
@tomayac fwiw, that post contains an error in the "Finding out if dark mode is supported" section. (prefers-color-scheme)
is supposed not to match if there's no preference for light or dark, so the right way to test whether it's supported is not window.matchMedia('(prefers-color-scheme)').matches
but window.matchMedia('(prefers-color-scheme)').matches || window.matchMedia('(prefers-color-scheme: no-preference)').matches
(or something like that). See w3c/csswg-drafts#3857 for more fun stuff related to that.
from loadcss.
Related Issues (20)
- FOUC on 'No Throttled' condition? HOT 2
- Polyfill has an issue in chrome
- Optionally preload without as attr?
- standalone or via npm?
- element with id `global` prevents loadCSS execution
- Error thrown by Content-Security-Policy HOT 5
- Supports preload
- Cannot use inline 'onload' because of CSP HOT 6
- The plugin doesn't do anything to preload elements in Firefox HOT 1
- Cannot install version 3.0.0 because node version is hardcoded to 11.9.0 HOT 5
- Where has the cssrelpreload polyfill gone in 3.0.0? HOT 2
- Required node version HOT 5
- Export onloadCSS
- CSS is being loaded twice HOT 3
- loadCSS not helping with render-blocking content
- Why do I sometimes get a recommendation in google pagespeed 'Reduce unused CSS' ? HOT 1
- Wouldn't loading css asynchronously cause FOUC? HOT 1
- Calling loadCSS from a TypeScript Vite application throws Uncaught TypeError: Cannot read properties of undefined (reading 'createElement') at loadCSS (loadCSS.js:13:16)
- Help - loadCSS/Critical file load not working
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from loadcss.