-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Event when CSS is loaded? #530
Comments
There will be always a race condition. To be honest the best way would be to use webpack for this and load only one JS file, which requires the slider.js and slider.css. I will have to work on this. |
Thank you very much for the reply and your suggestion. I'm fairly new to this kind of approach, Webpack seems very complicated too me, or let's say there are so many dependencies, it makes me uncomfortable. I checked curljs and liked it. This is how they seem to do it: |
You should really check webpack or parcel out! Also note you still can use it with lazyinclude. You can even use the window.lazySizesConfig.requireJs =(modules, cb) => {
import(`dynamic-imports/${modules}`).then(cb);
}; However can you check the following script?: https://gist.github.com/aFarkas/a6b2fa29204c30d673a89d7f3cf48f14 I now only include everything, if the last CSS was successfully loaded. But I haven't even tested it my own. |
@aFarkas wow thank you! It works like a charm for me in latest Chrome and Firefox. I think the curljs guys did some stuff to also support IE, the first 400 lines of their document are related to that: Would love to see this option in lazyload. It's not needed always, but sometimes it is, so having the option to wait for the css would be a crucial feature. |
test now |
Hi aFarkas, I've tested it and I am pretty happy with the result. It's not 100% reliable in all circumstances, but as soon as the css file sizes get realistic (ok I mean 350KB is crazy!!), it is reliable across Chrome, Firefox, Edge and IE11.
In Chrome and Firefox I also tested it with connection throttling, and then I got 100% reliable results even with the 900KB CSS file. I tested older IE versions and they worked great via BrowserStack. Also here the connection was poor in comparison to the other test that happened on my local machine. So I guess that makes a big difference... I'd say this is good enough to add it as an option! What do you think? |
Not good enough. I will need to write my own testcase to do the tests. Which means it will take some time to get this better. IE8 is not supported by lazysizes either. |
Hi!
congratulations aFarkas, great piece of code, very useful!
I'm using lazysizes as well as the includes plugin together with requirejs (and jQuery and Bootstrap).
It all works file, however when I try to load an amd module as well as corresponding css:
My issue is that I don't have one of these:
In the documentation it states that in case of content (content.html), this one will always be included first and then js/css will be loaded/executed.
In most of my tests it's fine, however if I have a slider.css file that is large in size and it changes the width of a div, it's impossible for me to read out this width from amd:slider, because none of the available event listeners waits until the CSS is loaded.
In this case it still works (reading out the CSS width of the element via JS):
![image](https://user-images.githubusercontent.com/1693855/44853594-a9c98c80-ac66-11e8-8c7c-d2c42ccd813c.png)
In this case it doesn't work anymore (reading out the CSS width of the element via JS):
![image](https://user-images.githubusercontent.com/1693855/44853655-cebdff80-ac66-11e8-9671-4cd712262c93.png)
Any chance this could be added? / Any idea what else to do?
Of course if my css file is just 5kb, all is fine. However I'd like to be in charge of the program flow and it shouldn't be based on coincidence.
Best Regards!
Daniel
The text was updated successfully, but these errors were encountered: