Comments (4)
many people have asked for this before. i have no plans to add it to LABjs at the moment, and here's why:
-
actually determining if a dynamically loaded CSS file has finished loading is actually quite complicated and challenging to do cross-browser. The "load" events don't fire as one would hope/expect. so adding such support would add a non-trivial size to LABjs (or to a LABjs wrapper/plugin).
-
I actually find it very rare that people need to sequence the loading (and "executing") of CSS in between the loading of other scripts. It's very common that someone says "I want to load these scripts and this CSS file" for widgets and things, but very rare that someone says "I need to load this script, THEN this CSS file, THEN this other script .... " LABjs is specifically for loading things in parallel and sequencing their execution for dependency sake. So it makes much less sense to mix in CSS loading (which usually doesn't need sequencing) into the API. Would be very much more confusing.
-
Just the dynamic loading portion (not the load-detection or execution sequencing) of CSS files is actually very easy to do. The code is like this:
var link = document.createElement("link");
link.setAttribute("rel","stylesheet");
link.setAttribute("type","text/css");
link.setAttribute("href","http://link/to/file.css");
document.getElementsByTagName("head")[0].appendChild(link);
Because that code is so trivially easy for people to do themselves if they want to load CSS dynamically, I don't think it belongs in a tool which is designed for the specific purpose of performance-efficient script loading.
All this having been said, some other loaders do support CSS loading... like Dominoes and RequireJS.
from labjs.
is there a way to know when the css has been loaded. so that i can make the div visible only when the callback has been fired.
from labjs.
The most straightforward way is to have a CSS style in the stylesheet and then to poll every 25 ms and look for the computed style of some element to see if that style has been applied. Obviously that's kind of ugly, but I've done that successfully before.
If you look in the source code for Dominoes there's a more complex solution that tries to actually detect if the stylesheet itself is loaded as a node in the DOM, and uses some interesting security behavior in various browsers.
Either way, it's not straightforward or easy. That's one of the reasons I've not put it into LABjs. The complexity is not worth the payoff.
from labjs.
closing (for now)
from labjs.
Related Issues (20)
- BOM issues HOT 4
- HTTP2 or SPDY and LABjs HOT 2
- swallowing errors doesn't seem right HOT 1
- It's nearing time for 3.0 HOT 31
- LAB inserts scripts at the beginning of the <head> HOT 7
- how to use LAB when Chrome blocks inline scripts ? HOT 2
- LABjs regular expression breaks for Windows apps
- Why not add localStorage to cache the scripts? HOT 6
- What is the role of first line?
- labjs.com is down HOT 1
- Recovering from 404 HOT 1
- Refactor out arguments.callee HOT 1
- huge longshot, but... might be a bug with LAB.js here. HOT 8
- www.labjs.com is not working
- LABjs blocking the executation of jquery each()
- setAttribute("as", "script") in chrome 51.0.2704.84 window7 messy code
- Seeking for a stable v3.0 package
- Current project status HOT 2
- [Question] Does LABjs scrub out the debugger keyword? HOT 2
- JsDelivr - I can't see '.js' files HOT 3
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 labjs.