Created
May 4, 2010 17:49
-
-
Save lucasmazza/389720 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 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