在浏览器中使用问号(?)结束访问CSS [英] accessing the CSS in browser using question mark (?) in end
问题描述
有人可以解释在浏览器中访问 CSS
有什么区别,在结尾放置问号?
为什么新的CSS不会对网站造成任何影响。
我在网络服务器上部署了一个新的 CSS
它不会产生任何影响。
我尝试在浏览器中打开以下网址:
www.mysite .com / styles / css / main.css
并加载旧版本 CSS
。
然后我尝试了如下,它加载了新版本的CSS。
code> www.mysite.com/styles/css/main.css?
完成所有这些。新的CSS更改不会影响网站。
您可以需要添加一些东西之后?然后在更改CSS时更改它。发生的是浏览器将缓存在特定时间内不更改的任何内容,它通过检查文件名来进行缓存。所以main.css?仍然是main.css?问号后面的任何内容都是查询字符串,通常用于将数据传递到特定文件。在这种情况下,它只是用于更改文件字符串,所以浏览器会更新它每次它更改,而不会影响文件本身。
有几种方法处理这个,第一个是手动更改版本,可能是最简单的想法,如果你有一个单一的头文件,如在模板系统总是加载相同的头数据。
< link rel =stylesheettype =text / csshref =assets / css / main.css?ver1 />
然后在下一次更改时:
link rel =stylesheettype =text / csshref =assets / css / main.css?ver2 />
如果你宁愿自动做,你可以添加一点PHP脚本到css行this:
< link rel =stylesheettype =text / csshref =assets / css / main。 css?time =<?php echo filemtime('./ assets / css / main.css');?> />
这本质上是添加一个值,每次保存文件时都会发生变化,下一次保存文件时,time =值将更改:
< link rel =stylesheettype = / csshref =http://localhost/refficient/trunk/assets/css/main.css?time = 1350305706/>
can someone explain what is the difference in accessing
CSS
in browser by putting question mark?
in the end and why the new CSS is not making any affects on Website.I have deployed a new
CSS
on web server but its not making any affect.I tried to open the URL in browser as below:
www.mysite.com/styles/css/main.css
and it loads the older version of
CSS
.Then I tried it as below and it loads the new version of CSS.
www.mysite.com/styles/css/main.css?
After doing all this. New CSS change does not affecting the website. Its still displaying the old design.
Kind Regards
解决方案You need to add something after the ? then change it when you change the CSS. What is happening is a browser will cache anything that doesn't change for a specific period, it does that by checking file names. so main.css? is still main.css? Anything after the question mark is a query string, generally it's used to pass data to a particular file. In this case it's just used to change the file string so the browser will update it every time it changes without affecting the file itself.
There are a couple of ways you can handle this, the first is manually changing the version, probably the easiest idea if you have a single header file, as in a template system that always loads the same head data.
<link rel="stylesheet" type="text/css" href="assets/css/main.css?ver1/>
Then on next change:
<link rel="stylesheet" type="text/css" href="assets/css/main.css?ver2/>
If you'd rather do it automatically you can add a bit of PHP script to the css line like this:
<link rel="stylesheet" type="text/css" href="assets/css/main.css?time=<?php echo filemtime('./assets/css/main.css');?>" />
This is essentially adding a value that changes every time you save the file and results in something like this, the next time I save the file that time= value will change:
<link rel="stylesheet" type="text/css" href="http://localhost/refficient/trunk/assets/css/main.css?time=1350305706" />
这篇关于在浏览器中使用问号(?)结束访问CSS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!