Anybody know if there’s a way to listen to when th...
# suitecommerce
j
Anybody know if there’s a way to listen to when the CMS has finished loading its content? I’m putting some JavaScript in using the CMS and I need to execute an event after everything has finished loading, but the sequence of events seems screwy…
s
j
Thanks @Steve Goldberg. Is that version-dependent, though? We’re still on Kilimanjaro.
s
I don't know when it was introduced, so I can't say
m
@Jacob D my team and I have been fighting this battle for years on Kilimanjaro, too. In our case we’ve routinely found that any JS on the CMS pages could be rendered 2+ times. Did you find that the
cms:rendered
event worked for you?
j
@Mike Herrera Not, really. I was never able to make anything happen with
cms:rendered
, at least on the page I was woking on at the time. I’m thinking it didn’t get added until a later version. I’m really encouraged by its existence, but I’m thinking we’re left behind in the upgrade cycle. What I ended up doing was pretty hacky, but it seems to work. I had a YouTube video embedded on the page and I noticed that it was always the last thing to load, so instead of using the standard iframe embed, I found that YouTube has an API that you can use to embed videos: https://developers.google.com/youtube/iframe_api_reference, along with a handy
onReady
event that I used to execute the code that I needed to run once everything was finished loading. Like I said, SUPER hacky, but it worked in my case because it was just some simple scroll events that we’re critical to the page operation. Super specific to my application, but I figured it might give you some ideas on ways to circumvent the Kilimanjaro restrictions.
m
@Jacob D I just tried a quick experiment with another dev —
cms:rendered
isn’t fired on Kilimanjaro. We’re currently relying on hacks, too. Lots of setTimeouts and setIntervals to check when the DOM has stabilized. Would consider bundling more into the project, but the bundle sizes are already pretty hefty.
j
@Mike Herrera Yep, I definitely went the setInterval route. On one page, I think I’m listening to see if the height of the main container div reaches a certain height threshold and executing code based on that. Good times…