0

I'm developing an ASP MVC Single Page Application with Visual Studio 2012. It uses components made of static JS / CSS / HTML files and loaded per need. The approach works great without even needing bundling in production, since statics is cached by the browser, but there is a problem in dev, since cache has to be disabled to refresh files I'm working on at the moment, and that means about 100 small static files are loaded with each page refresh taking about 40 seconds.

I'm currently lookin into Chrome Workspaces, but I think that a more universal viable solution is to specifically disable cache for files with modification date within last 30 minutes.

I'm looking for alternative solutions or an existing component to disable cache for recently modified files in VS / ASP (a custom HTTP handler?).

Cœur
  • 32,421
  • 21
  • 173
  • 232
Ivan Koshelev
  • 2,691
  • 2
  • 20
  • 37

1 Answers1

-1

Assuming you are using IIS or IIS Express, the simplest solution is just to disable caching entirely in your development environment by adding settings to your web.config file.

NOTE: If you have no web.config file, you can create one in your website's root directory.

<configuration>
  <system.webServer>
    <httpProtocol>
      <customHeaders>
        <add name="Cache-Control" value="no-cache" />
      </customHeaders>
    </httpProtocol>
  </system.webServer>
</configuration>

Alternatively, you can disable caching of files in a specific location of your website:

<configuration>
  <location path="path/to/the/file">
    <system.webServer>
      <staticContent>
        <clientCache cacheControlMode="DisableCache" />
      </staticContent>
    </system.webServer>
  </location>
</configuration>

In either case, you can use web config transformation during your release in order to remove these sections in your test/production environments.

<?xml version="1.0" encoding="utf-8"?>

<!-- For more information on using web.config transformation visit http://go.microsoft.com/fwlink/?LinkId=125889 -->

<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
    <!-- Use this section if you are disabling caching site-wide -->
    <system.webServer>
        <httpProtocol>
            <customHeaders>
                <add name="Cache-Control" value="no-cache" xdt:Transform="Remove" xdt:Locator="Match(name)" />
            </customHeaders>
        </httpProtocol>
    </system.webServer>

    <!-- Use this section if you are disabling per folder (duplicate if necessary) -->
    <location path="path/to/the/file" xdt:Transform="Remove" xdt:Locator="Match(path)">
        <system.webServer>
            <staticContent>
                <clientCache cacheControlMode="DisableCache" />
            </staticContent>
        </system.webServer>
    </location>
</configuration>

Reference: How do I disable caching of an individual file in IIS 7 using weserver config settings

Community
  • 1
  • 1
NightOwl888
  • 51,095
  • 20
  • 122
  • 194
  • We've already tried this, and it alleviates part of the problem, but only for 3rd party libs that reside in a separate folder. With components it is still 'all or mothing' if you cover their entire folder, or having to remember to switch path to the component you're currently working on - also not ideal. – Ivan Koshelev Jun 25 '16 at 23:29
  • You might want to check out the answers to [this question](http://stackoverflow.com/q/5690269/181087) for some options. – NightOwl888 Jun 26 '16 at 00:01
  • i've seen that one, but, afaics, proposed solutions are "all or nothing" approach, not what I'm looking for. – Ivan Koshelev Jun 26 '16 at 11:39