Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Proxy-friendly web caching.
C# Other
branch: master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
.nuget
WebCache.TestSite
WebCache
.gitattributes
.gitignore
README.md
WebCache.sln

README.md

WebCache

Static asset caching for websites. Faster sites, happier users.

Usage

Register assets on application start:

WebCache.Register(
    new Bundle
    {
        Name = "Header",
        Assets = new List<Asset>
        {
            new Asset("/assets/styles/main.min.css"),
            new Asset("/assets/styles/app.min.css"),
            new Asset("/assets/scripts/header.js")
        }
    },
    new Bundle
    {
        Name = "Body",
        Assets = new List<Asset>
        {
            new Asset("/assets/scripts/log.js")
        }
    }
);

Render bundles in your HTML:

@using WebCache
<!DOCTYPE html>
<html>
<head>
    <title>WebCache</title>
    @Html.RenderBundle("Header")
</head>
<body>
    <h1>WebCache</h1>
    <a href="/">Request page again</a>
    @Html.RenderBundle("Body")
</body>
</html>

Which produces:

<!DOCTYPE html>
<html>
<head>
    <title>WebCache</title>
    <link rel="stylesheet" href="/assets/styles/main.min.1d343cdc458745e8b092421272c3acd2.webcache.css" />
    <link rel="stylesheet" href="/assets/styles/app.min.aaf81fa9b555358807d986b3b225a06b.webcache.css" />
    <script src="/assets/scripts/header.d0844ec6fc5c98cda897d740b3840337.webcache.js" /></script>
</head>
<body>
    <h1>WebCache</h1>
    <a href="/">Request page again</a>
    <script src="/assets/scripts/log.37309cb1fc49681c1c20becff68312c6.webcache.js" /></script>
</body>
</html>

Add the HttpHandler to your web.config:

<system.webServer>
    <handlers>
        <add name="WebCache" verb="*" path="*.webcache.*" type="WebCache.WebCacheHttpHandler" preCondition="managedHandler"/>
    </handlers>
</system.webServer>

Kick back and relax, knowing your assests are sent compressed with long-lived cache headers.

Something went wrong with that request. Please try again.