System.Web.Optimization bundling css js caching

935 Views Asked by At

I am using System.Web.Optimization to bundle css and js files. So from what I understand System.Web.Optimization is caching js and css bundle on client side and that works fine. I checked my calls on fiddler first time when page loads for js and css bundle I am getting status 200 and next time its coming from client browser cache and there is no entry for js and css bundle in fiddler. But for images I keep getting status 304 unmodified everytime I load my page. I want to browser cache all my images as well that are coming from CSS. Does anyone know how to do that using bundling System.Web.Optimization? Thanks, Alkingson

2

There are 2 best solutions below

0
On

The System.Web.Optimization bundles are for CSS and JavaScript to combine into one call instead of many HTTP requests.

Have look into leverage browser caching :

What browser caching does is "remember" the resources that the browser has already loaded. When a visitor goes to another page on your website your logo, CSS files, etc. do not need to be loaded again, because the browser has them "remembered" (saved). This is the reason that the first view of a web page takes longer than repeat visits.

When you leverage browser caching, your webpage files will get stored in the browser cache. Your pages will load much faster for repeat visitors and so will other pages that share those same resources.

http://websitespeedoptimizations.com/LeverageBrowserCaching.aspx

1
On

The System.Web.Optimization bundles are for CSS and JavaScript. They don't have anything to do with caching images. You'll want to take a different approach to do that:

Option 1: Set it in the IIS settings in the web.config like this:

http://www.iis.net/configreference/system.webserver/staticcontent/clientcache

Option 2: If they are images that you are returning from code, you can set the cache headers as part of the response, like this:

http://forums.asp.net/t/1947339.aspx?How+to+cache+Images+at+client+side+