2

Below is my Fidler.

enter image description here

If you pay attention to the above screenshot, js and css files are being downloaded on every refresh. Why?

I have a query about the functionality of Combres. Url.Combress can cache the css files. right? In case you remove the css file from the physical location. I get 404 error? Why? Because this file is cached. So it should not be picked from it's physical location. Instead it should be picked from cache. Correct?


Explanation

I am using MVC3. I have installed Nuget Package combres in Package Manager Console

Install-Package combres.mvc

Below is the proof of my Route Table

enter image description here

I have below two files in my Layout.

<link href=""~/Content/Site.css" type="text/css" />
<script src="~/Scripts/jquery-1.7.1.min.js" type="text/javascript"></script>

Combress.xml setting

<combres xmlns='urn:combres'>
  <filters>
    <filter type="Combres.Filters.FixUrlsInCssFilter, Combres" />
  </filters>
  <resourceSets url="~/combres.axd"
                defaultDuration="30"
                defaultVersion="auto"
                defaultDebugEnabled="auto"
                defaultIgnorePipelineWhenDebug="true"
                localChangeMonitorInterval="30"
                remoteChangeMonitorInterval="60"
                >
    <resourceSet name="siteCss" type="css">
      <resource path="~/content/Site.css" />
    </resourceSet>
    <resourceSet name="siteJs" type="js">
      <resource path="~/scripts/jquery-1.7.1.min.js" />
    </resourceSet>
  </resourceSets>
</combres>

When i execute the below path

http://localhost:2474/Home/About

I think, it is downloading the above files every time. As per my understanding, combress should Cache the images/css/js file which ever files are mentioned in the combres.xml setting.

dove
  • 20,469
  • 14
  • 82
  • 108
SMC
  • 237
  • 1
  • 5
  • 29

1 Answers1

2

You need to reference the files differently. Since you are using asp.net-mvc I would recommend you also install this complementary nuget package

Install-Package combres.mvc 

And then in your master page, or wherever you want your different resources

@Url.CombresLink("siteCss")
@Url.CombresLink("siteJs")

Note : Before adding the above code lines. Add @using Combres.Mvc; in your layout Page.

This is the standard recommendation as per the documentation.

Note that you probably want to have full source in debug mode and only combine in release mode, which is a setting on your resourceSet: defaultDebugEnabled="auto"

There are other considerations but that should be enough to get started.

Imad Alazani
  • 6,688
  • 7
  • 36
  • 58
dove
  • 20,469
  • 14
  • 82
  • 108
  • I have a query about the functionality of Combres. Url.Combress we can cache the css files. right? In case you remove the css file from the physical location. I get 404 error? Why? Because this file is cached. So it should not be picked from it's physical location. Instead it should be picked from cache. Correct? – SMC Aug 15 '13 at 14:22
  • Combres will allow the file to be cached by the server, proxies and browsers but it does require that the file be present as well. It has to get it there the first time. Which cache were you thinking of? – dove Aug 15 '13 at 14:29
  • Yes, we are discussing Browser Cache. Yes. First time it is picking from the physical location. Then it should pick from the Browser Cache. But, not happening for me. Am I missing something. please let me know if you need more information. After deleting the file from physical location, it shows 404 in fidler. after second refresh. – SMC Aug 15 '13 at 14:39
  • if you're in localhost debugging then set defaultIgnorePipelineWhenDebug and defaultDebugEnabled to false. – dove Aug 15 '13 at 15:38
  • can u suggest for the image part also ? – SMC Aug 16 '13 at 07:25
  • host your images on a cookieless domain like SO does, http://sstatic.net/. you could use a CDN like cloudfront (there's many) – dove Aug 16 '13 at 08:34
  • In case I have to place image in same Website. Can you suggest some code please ? – SMC Aug 16 '13 at 16:20
  • that's a different question but take a read below to start, http://stackoverflow.com/questions/1368113/cache-control-header-browser-caching-iis7 – dove Aug 19 '13 at 07:15