Click here to Skip to main content
13,357,552 members (28,707 online)
Click here to Skip to main content
Articles » Web Development » Caching » General » Downloads


13 bookmarked
Posted 16 Jul 2012

JavaScript and CSS caching using CRC32

, 16 Jul 2012
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...

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