Giter Site home page Giter Site logo

aspnetmvc5-asset-versioning's Introduction

AspNet.Mvc.AssetVersioning

Adds a UrlHelper.VersionedContent URL extension helper to append SHA256 hash to content URLs in ASP.NET MVC 5.

Install

Install-Package AspNet.Mvc.AssetVersioning

Usage

In Views/web.config, add:

<configuration>
  ...
  <system.web.webPages.razor>
    <pages ...>
      <namespaces>
        ...
        <add namespace="System.Web.Mvc.AssetVersioning"/>
      </namespaces>
    </pages>
  </system.web.webPages.razor>
</configuration>

You can then use the helper in .cshtml files like so:

<script type="text/javascript" src="@Url.VersionedContent("~/scripts/jquery.js")"></script>

And the helper will append a query string parameter containing the SHA256 hash of the content. This is cached for the lifetime of the request cache (HttpContext.Cache).

aspnetmvc5-asset-versioning's People

Contributors

kamranayub avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

aspnetmvc5-asset-versioning's Issues

Possible issue with slashes

I am seeing generated version hashes like this:

/scripts/lib/jquery.js?/7Vw4usZo39WYsHCrdNjIFHX6JYo92Sg0aGXnWU6GrM=

And seeing reports in instrumentation logs of browser console errors with this script seemingly undefined -- correlation not causation but seems worth it to spit out hex-only hashes or something more friendly.

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.