question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Hi,

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:closed
  • Created 5 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
amoreycommented, Sep 14, 2018

Async refers to the async property on <script> tags. When async=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 an async property so setting the LoadJS async 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.

1reaction
amoreycommented, Sep 14, 2018

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Word Usage Practice Test Questions
You'll love our free Word Usage practice questions. (Set 1) Get the help you need on your exams.
Read more >
Word- Usage Question Type | QS-LEAP
Word-usage questions as the name implies, tests your understanding of the correct usage of words. In the passage, you will come across ...
Read more >
The Uses of Question Marks in English Punctuation
Use the question mark when posing a direct query in an interrogative sentence. This denotes that the speaker is seeking information. Are there...
Read more >
Question Mark: Rules, Usage, and Examples - ProWritingAid
A question mark replaces a period at the end of a sentence when the sentence is a question. Sometimes, question marks are known...
Read more >
Do vs Does Questions - English Grammar Rules
To make a question in English we normally use Do or Does. It is normally put at the beginning of the question (before...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found