How to enable caching for JS, CSS files in Azure CDN for Azure App Service (Website)

1.8k views Asked by At

I set up Azure CDN for Azure app service, and all works fine except caching. I added the clientCache node as described here.

<clientCache cacheControlMaxAge="30.00:00:00" cacheControlMode="UseMaxAge" />

And also set up bundles for the CDN.

The result is:
Cache works for jpeg, png.

Cache-Control:max-age=2592000

But for js and css files I get the following headers:

Cache-Control:no-cache
Expires:-1
Pragma:no-cache

Thanks for any help.

1

There are 1 answers

0
Cephas Lin On

From my test, it looks like Azure already enables caching of js/css caching by default. I get Cache-Control:max-age=2592000 if I simply use the <clientCache> tag.

Are you saying that you're getting Cache-Control:no-cache from the bundled scripts/css? You should just get Cache-Control:public on the bundles.

I did notice that I would get Cache-Control:no-cache if I started playing with caching profiles. But that's a moot point because Azure enables js/css caching by default.