Hi All, I had a doubt regarding usage of "settimeo...
# suitecommerce
p
Hi All, I had a doubt regarding usage of "settimeout", where I have used settimeout for loading third party library say swiper.js where the library gets loaded before the DOM rendering, So in this case many times the swiper fails to initialise the mechanism as the class wrt this is still not rendered in the DOM so in such case settimeout of 1 sec can be recommended ? We have already wrapped it inside !SC.isPageGenerator to ensure that it doesn't cause seo to break. I read in a suitecommerce doc for seo best practices that "You should not use the 
setTimeout()
 and 
setInterval()
 methods on the SEO page generator because they might cause the SEO page generator to timeout." So it it advisable to exclude setTimeOut from seo or is it advisable to not use it at all.
s
The
SC.isPageGenerator
value is used to execute JavaScript either exclusively in a human user's browser or in a bot's browser. Depending on what your library does you may want to use it for that purpose (eg if it is just a visual enhancement, like a loading indicator, then you can prevent it from running in a bot's browser).
If you want to make sure that your library code executes after the page is rendered then use that event. You can use
jQuery(document).ready(...)
or you can use a Backbone event to listen to, for example, the page layout or a specific child view has been rendered.
p
We tried using jQuery(document).ready(...) and even events like afterViewRender, but both of them didn't work
s
Didn't work how?
p
as in the element that i was trying to access was not found when the script executed. Adding a timeout of 1 sec the same script executes properly.
this become even more problematic when trying to add some kind of interaction to markup that comes from cms area