Replies: 6 comments 2 replies
-
Hello @morvy Can you give me more specific details on how to use the library with your idea? I'm wondering if you need to use the waitForUserAction option when you want your resources to load or execute even without user interaction on your website. You can certainly load or execute certain scripts without the waitForUserAction option, such as tracking scripts, for example. I think it would be better if you give some specific examples, so I can consider whether it's necessary to implement your idea versus keeping my library small and lean. |
Beta Was this translation helpful? Give feedback.
-
Hello :) currently I use a script to load iframe (which then loads tons of styles, fonts..) on homepage above footer.
But this means it waits 400ms and executes. As there is waitForUserAction set to true, it waits forever and no widget is loaded. If I set it to false, widget is loaded after 400ms but that won't help with page speed.
So there are 3 things that can happen (I hope):
OR .. 2nd option could behave as I originally understood the function. If 400ms + true, waits for user action but execute after 400ms if there was none. |
Beta Was this translation helpful? Give feedback.
-
Hi @morvy I have tried implementing the idea based on the third option you suggested. Could you please help me evaluate whether it is working as you expected? README: https://github.com/shinsenter/defer.js/blob/develop/README.md#Defer.lazy Since the library size has increased significantly (nearly 100 more bytes), I am considering ways to reduce the size before the official release. Best regards |
Beta Was this translation helpful? Give feedback.
-
@shinsenter it works great. Just a note to the behavior. When I first tried the script I was under impression that it loads a script from src, waits for 500ms and if lazy=false, executes always after 500ms. If lazy=true, executes anytime between 0ms and 500ms, depending if user interacts instantly or not. With 2 timeouts, this can handle cases when user interacts instantly, but there are scripts that can be loaded a bit later, so they don't overload the browser with irrelevant stuff in the footer etc. Thanks a lot! |
Beta Was this translation helpful? Give feedback.
-
@morvy |
Beta Was this translation helpful? Give feedback.
-
Not sure what you mean by adjusting the explanations as these 2 points explain everything. Note: (2) Lazy loading behavior changed since v3.0 when you set Defer.lazy=true or waitForUserAction=true. A <script> tags with type="deferjs" will not execute unless the user starts interacting with your page. Maybe I'd add a use-case. Like: A typical scenario might involve an iframe, chat window, or event tracking scripts.
|
Beta Was this translation helpful? Give feedback.
-
Hi,
would it be somehow possible to extend the default behavior of waitForUserAction so if there is no interaction in limit, it will still load the script/css/dom ?
I noticed that on a page where I have waitForUserAction enabled, some users only open in new tab and leave it there for a while, then come back and the page starts loading (or they close the tab and scripts don't trigger at all).
Beta Was this translation helpful? Give feedback.
All reactions