ie7 is not loading my stylesheet

2019-06-25 14:25发布

问题:

I have a page that works on firefox and chrome. In IE7 i'm experiencing a rather interesting behavior, the stylesheet does not load. However, if I press CTRL F5, it does.

This is very annoying to say the least.

Anyone experience this issue? any recommendations?

FYI: The page uses JQuery and plain javascript, has CSS elements positioned absolutely and relatively throughout, conditional HTML (to separate IE specific javascript because IE7 will not respond well to a few jQuery effects when combined with IE shadow filter and also to load an IE-specific stylesheet which addresses some of the f-ed up positioning-related spec violations).

回答1:

IE is just caching the css and not checking for a new one since it has the same name. In order to force the new css to load, you will have to change the name. Often times people will do a versioning number to get around this bit of IE:

mySheet.001.css
mySheet.002.css
...etc.

This way it will be reloaded for all of your users the first time you change the version number - just be sure to change the reference as well.



回答2:

A good trick to prevent caching is to use a query string on the CSS file.

Try:

<link rel="stylesheet" type="text/css" href="style.css?v=00001" />

If you sequence the number when you make a change it will automatically redownload the css file without you needing to rename it. You can also do this for images and other files.

EDIT: I find it even more useful if you have a frequently changing site to use the date as the string rather than version numbers. Just makes it a bit more human readable.

i.e.

<link rel="stylesheet" type="text/css" href="style.css?v=130906-1" />


回答3:

Did you try to change IE cache settings?



回答4:

@naspinski: No. xmars wrote that he cleared the cache. Problem does not consider seeing changes after update. Do not propose to use CSS name exploit. Cache is there for something, it is for providing higher efficiency while site is not updated, and one should be able to benefit from this solution. Additionally Etag is proper mechanism that should be used to trigger client updates, not some sloppy workarounds.

@xmars: IE7 has no known, reported, reproduced and documented bug regarding linking cascading style sheets in conditional comments. Either you are a mighty bug finder, or simply wrong. I vote second. Link here your documents. Let's take a look on them.