• 10.0.0 - 10.0.26
    541 201 9965 Email Website
  • Contents
    Search:
     

    Home > Development Notes > Cache Control Header

    Cache Control Header

    Specifying a Cache-Control header allows your server to tell browsers that it is okay to cache resources from the website for a given amount of time. That way the browser doesn't have to ask for an image or file again after it already got that resource the first time that they loaded the website. This can really boost your website's perceived performance to your end users. Caching is always a bit tricky though so we encourage to do a bit of research on the Cache-Control header before you turn this feature on.

    Modifying the web.config

    We've added a commented out section of the web.config that allows you to specifiy a Cache-Control header for all images on the website. Search for the following block of code in he webconfig and remove the xml comments to enable it:

    <!--<outboundRules>
        <rule name="Set Cache-Control header for image files">
            <match serverVariable="RESPONSE_Cache-Control" pattern=".*" />
            <conditions>
                <add input="{REQUEST_FILENAME}" pattern="\.(jpg|png|gif|bmp)$" ignoreCase="true" />
            </conditions>
            <action type="Rewrite" value="max-age=604800"/>
        </rule>
    </outboundRules>-->
    

    Remove the comment tags like so:

    <outboundRules>
        <rule name="Set Cache-Control header for image files">
            <match serverVariable="RESPONSE_Cache-Control" pattern=".*" />
            <conditions>
                <add input="{REQUEST_FILENAME}" pattern="\.(jpg|png|gif|bmp)$" ignoreCase="true" />
            </conditions>
            <action type="Rewrite" value="max-age=604800"/>
        </rule>
    </outboundRules>
    

    Max Age

    The max age is in seconds. The one we ship with specifies that a browser should cache the wesite image files for one week (60 seconds x 60 minutes x 24 hours x 7 days).You can adjust the max-age to whatever makes sense for your website.

    File Types

    By default we only include image files in the rewrite rule. If you want to add additional file types to this list you can ajust the regular expression in the code above to include the file type you are targeting. If you want to add cache-control headers to css and js files we recommend that you instead use our bundling and minification feature. This feature will get you a cache-control header in addition to other performance boosting functionality.



    Actions
    Print This Article
    Bookmark
    Email This Article
    Previous Article
    Next Article