Jun 26, 2020

Dealing With Cached CSS Files

If a stylesheet is updated and sent to prod, the customer's computer usually won't get the updated version for a while since their computer has a cached version of that file on their machine. This can often make the website look bad. There is a super simple solution to this. Adding a query string to the css request request makes the browser think it is a different file, even if the server still gives the same file regardless of the query string.

<link rel="stylesheet" href="/assets/css/main.css?version=20200626" />

Learnt this from Gordan of WPReset, who was a bit more verbose about this problem and solution.

No comments: