Usage question
See original GitHub issueHi,
A third party plugin inside my site needs to know if certain CSS file was already loaded. On my website I use this code below to load CSS styles:
loadjs(
["https://cdn.jsdelivr.net/npm/semantic-ui@2.3.1/dist/semantic.min.css","css!//fonts.googleapis.com/css?family=Montserrat|Raleway:400,700|Abel|Libre+Baskerville:400i","estilos.css"],
{
success:function(){
},
async:true
}
);
I know I can use the success callback to make sure the CSS were loaded HOWEVER this third party plugin has no access to my code and I dont it to have any access. So using the success callback is out of the way.
Then, after searching A LOT, I discovered that the code below would tell me if the CSS was already loaded:
$("link[href*='semantic.min.css']").length == 0 ? alert('not loaded'); : alert('loaded');
BUT I am not sure how LOADJS library works! I would like to know if LOADJS library would only place the LINK element at the DOM after the script is downloaded OR if it places the LINK element at the DOM before downloading it.
If it’s the first scenario I should be fine, but if it’s the second I should keep searching to find a better way!
Thanks!
Issue Analytics
- State:
- Created 5 years ago
- Comments:7 (4 by maintainers)
Async refers to the
async
property on<script>
tags. Whenasync=false
, the browser will download files in parallel and execute them in series so you would expect tags to get added to the DOM immediately even if execution is delayed.<link>
tags don’t have anasync
property so setting the LoadJSasync
option has no effect on them. However this doesn’t matter because the CSS style rules are applied in order of<link>
tags in the DOM regardless of when the files loaded.Please note that the LoadJS success callback won’t execute until all the files are finished downloading so if one of your CSS files takes 20 seconds to download, the callback won’t execute until then even if the other files have already been loaded in the DOM.
Are you running the test before/after the
DOMContentLoaded
event has fired? Depending on how you’re running the test you might be not be testing for the general case.