Git Product home page Git Product logo

cachebusting's Introduction

CacheBusting

Helpers to fingerprint urls to static resources

##Installation

http://nuget.org/packages/CacheBusting/

Install-Package CacheBusting

##Usage

<link href="@CacheBusting.FingerPrint.WithFileDate("/css/main.css")" rel="stylesheet"/>

or

<link href="<%= CacheBusting.FingerPrint.WithFileDate("/css/main.css") %>" rel="stylesheet"/>

Will render the following

<link href="/css/main.css?v=150414161025" rel="stylesheet"/>

It is also possible to not use the querystring for versioning, then some handler or redirectmodule is needed to resolve the url.

<link href="@CacheBusting.FingerPrint.WithFileDate("/css/main.css", false)" rel="stylesheet"/>

Will render the following

<link href="/css/main.150414161025.css" rel="stylesheet"/>

##Url rewriting

You can use the IIS Url Rewrite Module, that can be installed with the Web platform Installer. Then configure with this config to make the above urls work. (Example from Html5boilerplate IIS server config, with added file exists check)

<system.webServer>
  <rewrite>
    <rules>
      <rule name="Cachebusting">
        <match url="^(.+)\.\d+(\.(js|css|png|jpg|gif)$)" />
        <conditions>
          <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
        </conditions>
        <action type="Rewrite" url="{R:1}{R:2}" />
      </rule>
    </rules>
  </rewrite>
</system.webServer>

If you also deliver resources with virtual paths that does not exist on disk you can get trouble with the above rewrite rule, to make it compatible you can change the match regexp to only match exactly 12 numerics.

<match url="^(.+)\.\d{12}(\.(js|css|png|jpg|gif)$)" />

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.