Skip to content

Instantly share code, notes, and snippets.

@lucasmazza
Created May 4, 2010 17:49
Show Gist options
  • Select an option

  • Save lucasmazza/389720 to your computer and use it in GitHub Desktop.

Select an option

Save lucasmazza/389720 to your computer and use it in GitHub Desktop.
// Cachebuster for C#
private const string LinkTag = "<link href=\"{0}\" type=\"text/css\" rel=\"stylesheet\" />";
private const string JavascriptTag = "<script src=\"{0}\" type=\"text/javascript\"></script>";
private String MapAsset(String url)
{
FileInfo file = new FileInfo(Server.MapPath("~" + url));
String format = file.Extension == ".js" ? JavascriptTag : LinkTag;
url = file.Exists ? String.Format("{0}?{1}", url, file.LastWriteTime.Ticks) : url;
return String.Format(format, url);
}
//<link href="/path/to/your/stylesheet.css?lastwritetime" type="text/css" rel="stylesheet" />
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment