I’m trying to get all stylesheet to look like:
<link href="style.css?v=1234" rel="stylesheet" type="text/css" />
The only problem I’m running into is getting the current link tag and then applying the new random number to the current path. I think my method of applying finding the link is ok, but getting the current attr and then applying a new one is where I’m going wrong.
$(document).ready(function() {
var randomNum = Math.ceil(Math.random()*2);
// is this the best way?
$("head").find("link").attr("href")+"?v="+randomNum;
// I don't think this works
$('link[rel="stylesheet"]').end()+"?v="+randomNum;
});
I have a bunch of people who are experiencing cache problems and they noted that this would be a possible solution.
You were not setting the value back to the link. You can use a function to set the link value like below.