开发者

Dynamically created stylesheets not (always) updating, causing style flickering

开发者 https://www.devze.com 2023-01-08 02:47 出处:网络
I have a php script that loads a CSS stylesheet, changes the color attribute and then creates a 开发者_StackOverflow中文版new CSS file with the new color and links it to the page.

I have a php script that loads a CSS stylesheet, changes the color attribute and then creates a 开发者_StackOverflow中文版new CSS file with the new color and links it to the page.

When I hit refresh it sometimes updates to reflect the changes, sometimes it doesn't. At first I thought it was the cache, so I disabled caching in Safari but its still happening.

I was wondering if any of you have come across this, and if you have a solution for me.

Thanks! Matt


CSS is notorious for caching. Even what you did may not stop it from caching

A surefire way to reload the CSS is to do this:

<link rel="stylesheet" type="text/css" href="MyStylesheetScript.php?version=1" />

Simply ignore the query string in your sript. Changing its value (2, 3, 4) each time that you change the CSS will force all browsers to reload the CSS.

If it doesn't change after that, then the problem is your CSS :)

0

精彩评论

暂无评论...
验证码 换一张
取 消