I was fine tuning a page that is heavy on jquery and stumbled across this website:
.html
When I click on the "Run Test" button the first time, the numbers are way higher than subsequent clicks. Is this because JS is cached by the browser? Can someone explain how this works internally? Can a user choose to not cache the JS?
I was fine tuning a page that is heavy on jquery and stumbled across this website:
http://www.ponenthouse./extra/jquery-analysis.html
When I click on the "Run Test" button the first time, the numbers are way higher than subsequent clicks. Is this because JS is cached by the browser? Can someone explain how this works internally? Can a user choose to not cache the JS?
Share Improve this question asked Sep 4, 2009 at 16:10 NickNick 7,52521 gold badges79 silver badges129 bronze badges 2- All my tests in 5 browsers returned stable values. I beleave your first test was slower because you were loading something else at the same time during this first test. – Havenard Commented Sep 4, 2009 at 16:22
- given link was broken – ManirajSS Commented Aug 5, 2014 at 11:45
4 Answers
Reset to default 3External javascript files are cached and, of course, an html containing script tags can be cached too. What you see may be a result of html caching or some browser optimization. You should try different browsers, closing and re-opening your browser and clearing the cache of the browser.
The numbers are (significantly) different for me on the second time in Firefox 3.5. OTOH, they are fairly consistent(ly slow) in IE 8. Firefox 3.5's JavaScript interpreter piles the JS to executable code. So it does make sense that the first time is slower; the code hasn't been JITted yet.
The performance boost you're seeing is likely due to your javascript interpreter. Most newer web browsers use a JIT-piling javascript engine so code paths taken multiple times can be optimized.
Read this blog post on how Safari's javascript engine achieved many of its speed-ups.
Whether or not JavaScript code is cached, execution performance isn't affected. What you are seeing is jQuery caching the results for the selector queries so they don't take as long on subsequent runs.