views:

114

answers:

2

Let's say because of a conditional comment or just being careless the same included file is present for users of some browser or even all browsers. For example:

<!--[if lte IE 8]>
     <script src="mygreatincludefile.js" type="text/javascript"></script>
<![endif]-->

<!--[if lte IE 6]>
     <script src="mygreatincludefile.js" type="text/javascript"></script>
<![endif]-->

When the page is being rendered will the browser know not to bother to grab that file again or will it make a request and the browser will return 304 (not modified). The best case seems to be the first, the acceptable case seems to be the second option while the worst case would be that a fresh request would like be made because the browser doesn't know it just grabbed this yet.

Do you have experience with this sort of thing firsthand? What would you expect to happen? What have you observed happened? Should I just be not worrying about this and punch the person who did it keeping in mind that it may have been me?

+6  A: 

The file should be fetched once in most user-agents (including IE) but in the case of JavaScript, the code will be executed twice. The best example would be <img> tags. Images will load once, but can be used multiple times.

As for your example. It seems vain to do the same operation twice. You are basically saying "if less than or equal to IE8", then proceed to load the same file "if less than or equal to IE6", which it automatically will if it triggered the first rule.

Andrew Moore
I know. I realize what's it's doing. I just wanted to bring it up because I didn't see this question on here and it's a big topic these days. I also wanted to know how annoyed I should be with myself (if I did indeed do this, of course) about this. Thanks!
Jon
+2  A: 

Have a look at Fiddler to debug your http activities. There is also the IE Developer Toolbar for ie6/7 (ie8 has its own) or FireBug in FireFox.

These will enable you to view your requests and confirm your assumptions and the responses of other people.

Now, depending on if any http headers are specified notifying the browser not to cache anything, then the assumption would be that only 1 request would be made for the resource if that resource does not already exist on disk. The afore mentioned utilities will be able to confirm this for you.

Wayne