What is the purpose of using php inside css link t

2019-08-28 01:53发布

问题:

I've come across this recently and don't understand. I've Googled, but not sure what I should be Googleing to find answers to my questions.

<link type="text/css" rel="stylesheet" href="css/global.css<?=$debug?'?'.rand():''?>" />

I noticed something like this broke an entire website's styles.

回答1:

This appends a random number to the CSS URL if debug mode is on.
It's done to break caching.



回答2:

That particular php code intends to avoid that CSS resource being stored in a browser's cache. That's because you add a random string as a parameter to the HTTP request, (more technical details)... in the end it always looks as a different file to the browser, so it downloads it again



标签: php web