浏览器将不会读取更新的CSS [英] Browsers won't read updated CSS

查看:109
本文介绍了浏览器将不会读取更新的CSS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

编辑:我真诚的道歉!这不是一个问题,除了自己 - 我有一个global.css文件与正确的东西,但在下面,我包括与旧的CSS中的另一个文件,在< head> 我的HTML的位。 Facepalm。

My sincere apologies! This wasn't an issue with anything but myself - I had a global.css file with correct stuff in it, but below that I included another file with the old CSS in it, in the <head> bit of my HTML. Facepalm.

我有一个我正在开发的网站。我使用LESS来增强我的CSS,使它更容易写。问题是,当我更改 .less 文件时,浏览器中呈现的样式拒绝更改。我看过生成的 .css 文件,并且更新以反映所做的更改,但是浏览器不会从CSS文件更新它的呈现样式。我试过这个在Chrome,FF(3和4)和Opera,与相同的非更新结果。

I have a site I'm developing. I'm using LESS to enhance my CSS to make it easier to write. The problem is, when I change the .less file, the styles rendered in the browser refuse to change. I've looked in the generated .css file, and that updates to reflect the changes made, however the browser doesn't update it's rendered style from the CSS file. I've tried this in Chrome, FF(3 and 4) and Opera, with the same non-updating results.

我甚至告诉浏览器缓存没有,都用PHP和元标签,没有效果。我的Apache配置文件几乎是香草,虽然我使用多个本地主机(这是一个本地服务器)。用于将LESS转换为CSS的代码如下所示,并在每次重新加载页面时运行:

I've even told the browser to cache nothing, both with PHP and meta tags, to no avail. My Apache config file is almost vanilla, although I am using multiple localhosts (this is a local server). The code used to convert LESS to CSS is given below, and is run every time the page is reloaded:

try 
{
    lessc::ccompile('global/global.less', 'global/global.css');
} 
catch(exception $ex) 
{
    exit('lessc fatal error:<br />' . $ex->getMessage());
}

这里没有例外。 less.php 解析器检查文件是否已被修改,我删除了一点,但CSS文件是重新生成每次更改,因此这必须是缓存问题与浏览器某处... Apache提供更新的CSS文件只是罚款: - /

There are no exceptions here. the less.php parser checks if the file has been modified, which I removed for a bit, but the CSS file is re-generated on every change, so this must be a caching issue with the browser somewhere... Apache serves up the updated CSS file just fine :-/

对不起,继续这么久,但我想要清楚。

Sorry to go on for so long, but I wanted to be clear. If you need anything else, do let me know.

推荐答案

一旦我在代码中看到使用timestamp来强制浏览器以每个请求下载 css 文件:

Once I saw in a code the use of timestamp to force the browser to download the css and js files every request, that way:

<link rel="stylesheet" type="text/css" href="http://www.example.com/style.css?ts=<?=time()?>" />

?ts = 123456789

所以我采用了这个想法,而不是现在的时间戳,我使用文件修改的时间戳 style.css ;因此它在浏览器中缓存,直到在服务器上修改:

So I adopted the idea, but instead of timestamp of now, I use timestamp of the modification of file style.css; so it's cached in the browser until be modified on the server:

<link rel="stylesheet" type="text/css" href="http://www.example.com/style.css?ts=<?=filemtime('style.css')?>" />

这篇关于浏览器将不会读取更新的CSS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆