简体   繁体   中英

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

<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.

Question:
How do I get the latest revision date/time from my css file with php/smarty/javascript?

You could use php's 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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