When building advanced JS-interfaces and games I've found that I have to dig deeper in to how browsers handles memory for JS. My experience with memory and JavaScript is that the memory gets glogged (and makes animations and calculation slow/lagging ) when:
I have therefore concluded that if I want to keep my memory fresh I should include as much HTML code as possible from the beginning of the document as it will be cached and not kept in memory. And off course remove all currently not used elements.
Does anyone have any more info on this? Resources? Links?
Some things to keep in mind:
Generally, javascript itself is not a performance bottleneck. What kills it is the interaction with the DOM. Code that doesn't touch the DOM rarely has performance issues. There are only rules of thumb here: interact with the DOM as rarely as possible, keep DOM complexity as low as possible, avoid repeated page reflows.
For starters. All HTML, whether it is "include from the beginning" or not, is kept in memory. Most likely also all image content for the current page. At a bare minimum, everything that you see on-screen at any given time is kept in memory at that time.
It tends to depend more on what you're doing with it to be honest. A lot of graphics aren't going to do squat to javascript if you aren't interacting with them but if you've got an enormous page filled with different elements and you're searching the entire document for a single element then that's a different thing entirely.
I've had problems doing things like adding massive amounts of events to pages. Running too many loops in a page and too many timers.
If javascript performance is an issue and you're planning on doing intensive javascript, you might want to look at webworkers. Here's a few more links on webworkers:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With