Click here to Skip to main content
11,640,125 members (67,661 online)
Click here to Skip to main content
Articles » Web Development » Caching » General » Downloads
Add your own
alternative version

JavaScript and CSS caching using CRC32

, 16 Jul 2012 MIT 14.4K 157 13
A simple method to ensure that new .JS and .CSS files always get downloaded and cached ones never get re-downloaded.
using System.IO;
using System.Web;

namespace WebCRC
    public static class CRC
        public static string Content(this System.Web.Mvc.UrlHelper Url, string Path, bool CRC)
            if (!CRC)
                return Url.Content(Path);

            string serverPath = HttpContext.Current.Server.MapPath(Path);
            byte[] fileContents = File.ReadAllBytes(serverPath);
            string result = CRC32.Compute(fileContents).ToString("X");
            return Url.Content(Path) + "?crc=" + result;

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.


This article, along with any associated source code and files, is licensed under The MIT License


About the Author

Web Developer
United States United States
Paul Reid is the CEO (and still part-time programmer) of Product4Me Corporation, a web site company devoted to helping consumers get the individualized best fit for home theater (and other) products.

You may also be interested in...

| Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.150731.1 | Last Updated 16 Jul 2012
Article Copyright 2012 by PRMan!!!
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid