Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6920575
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T10:09:55+00:00 2026-05-27T10:09:55+00:00

I am having trouble with my static content being cached on the client (by

  • 0

I am having trouble with my static content being cached on the client (by static I mean js,css,jpeg,gif, etc). (and by client I mean its my development machine most of the time).

As a result, page is either throwing a script error, or not displaying correctly. I am not a Rails developer but I read a few books about it back in time. One thing I remember well is that it appends some magic version number to the end of the included file, so it becomes

<script src="~/Scripts/Invoice.js?201112091712" type="text/javascript"></script>

and if you modify that content file it generates a new version number, so it generates a different include statement, as a result, client thinks it is a new content, and it loads it without checking its cache.

Does asp.net-mvc 3 & IIS 7 support this, or do you know any tools that mimic this behaviour?

Thanks, Hazım

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T10:09:55+00:00Added an answer on May 27, 2026 at 10:09 am

    I have this done already in one of my projects, feel free to use my helpers if you like them :

    public static class VersionedContentExtensions
    {
        public static MvcHtmlString VersionedScript(this HtmlHelper html, string file)
        {
            return VersionedContent(html, "<script src=\"{0}\" type=\"text/javascript\"></script>", file);                     
        }
    
        public static MvcHtmlString VersionedStyle(this HtmlHelper html, string file)
        {
            return VersionedContent(html, "<link href=\"{0}\" rel=\"stylesheet\" type=\"text/css\">", file);
        }
    
        private static MvcHtmlString VersionedContent(this HtmlHelper html, string template, string file)
        {
            string hash = HttpContext.Current.Application["VersionedContentHash_" + file] as string;
            if (hash == null)
            {
                string filename = HttpContext.Current.Server.MapPath(file);
                hash = GetMD5HashFromFile(filename);
                HttpContext.Current.Application["VersionedContentHash_" + file] = hash;
            }
    
            return MvcHtmlString.Create(string.Format(template, file + "?v=" + hash));
        }
    
        private static string GetMD5HashFromFile(string fileName)
        {
            FileStream file = new FileStream(fileName, FileMode.Open);
            MD5 md5 = new MD5CryptoServiceProvider();
            byte[] retVal = md5.ComputeHash(file);
            file.Close();
    
            StringBuilder sb = new StringBuilder();
            for (int i = 0; i < retVal.Length; i++)
            {
                sb.Append(retVal[i].ToString("x2"));
            }
            return sb.ToString();
        }
    }
    

    use them like this :

    @Html.VersionedScript("/Scripts/sccat.core.js")
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm having trouble accessing the content of QNetworkReply objects. Content appears to be empty
I am having trouble getting dynamic content coming from a custom handler to be
I having trouble serving Django's static admin files on webfaction. Here's how I'm currently
I'm having trouble understanding how the static analyzer in XCode is identifying possible leaks
I'm working through the random machine example , but I'm having trouble. I've installed
Having trouble linking the Stomp.framework into an iPhone SDK application. http://code.google.com/p/stompframework/ I follow the
Having trouble with proper regex for RewriteCond RewriteCond %{REQUEST_URI} !^/foo/ Works as expected, that
Having trouble with the following segment of code. I'm getting a parameter count mismatch.
Having Trouble with Entity Framework. I have been populating EntityReferences with an EntityKey inorder
Im having trouble using a .NET COM in vb6, It compiles ok and I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.