views:

215

answers:

3

Do browsers (IE and Firefox) parse linked javascript files every time the page refreshes?

They can cache the files, so I'm guessing they won't try to download them each time, but as each page is essentially separate, I expect them to tear down any old code and re-parse it.

This is inefficient, although perfectly understandable, but I wonder if modern browsers are clever enough to avoid the parsing step within sites. I'm thinking of cases where a site uses a javascript library, like ExtJS or jQuery, etc.

A: 

I think that the correct answer would be "not always." From what I understand, both the browser and the server play a role in determining what gets cached. If you really need files to be reloaded every time, then I think you should be able to configure that from within Apache (for example). Of course, I suppose that the user's browser could be configured to ignore that setting, but that's probably unlikely.

So I would imagine that in most practical cases, the javascript files themselves are cached, but are dynamically re-interpreted each time the page loads.

Zachary Murray
A: 

My 2c: I feel the performance benefits of caching parsed Javascript files are too small for this to be a meaningful optimization.

Itay
+2  A: 

I'm pretty sure it is parsed every time. If you think about it, there could be a lot of variable factors that can change each time a page is loaded. Server-side scripts could change the DOM, variables could be set based on time or cookies. Since these variables could affect other variables which could affect other variables (and so on), it would make sense to fully parse each script every time the page is refreshed.

Andy E