简体   繁体   English

如何获取我的css文件的最新修订日期?

[英]How can I get the latest revision date of my css file?

Situation: My CSS was getting cached which was really annoying so I solved it this way 情况:我的CSS被缓存了,这真的很烦人所以我这样解决了

<link rel="stylesheet" href="/css/screen.min.css?{$smarty.now}" type="text/css" />

But now it reloads it every single time, what I want now is to only reload when there are changes. 但现在它每次重新加载它,我现在想要的只是在有变化时重新加载。

So, what I was thinking was instead of {$smarty.now} use something that gives me the latest revision date/time. 所以,我在想的不是{$smarty.now}而是使用能给我最新修订日期/时间的东西。

Question: 题:
How do I get the latest revision date/time from my css file with php/smarty/javascript? 如何使用php / smarty / javascript从我的css文件中获取最新修订日期/时间?

You could use php's filemtime() . 你可以使用php的filemtime() This function will get the last modification time of your file, which wouldn't change unless changes were made to the file. 此函数将获取文件的最后修改时间,除非对文件进行了更改,否则不会更改。

You would do something like: 你会做的事情如下:

<link rel="stylesheet" href="/css/screen.min.css?{$filemtime("/css/screen.min.css")}" type="text/css" />

The first forum item for this function in the documentation is a exact solution for your problem. 文档中此功能的第一个论坛项是您问题的精确解决方案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM