Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Controlling cache in Azure static web site

I'm playing with Azure Static Web Site (new feature of storage account).

This works well for servicing files. However, I didn't found where I can set cache control headers (if it's possible).

Basically, I want to set no expire cache to static bundled javascripts (hash of files are in file name), but not on html pages.

How to reach my goal ?

PS: I'm not using Azure Web Sites, but Azure static web site option of blob storage. Unless web.config are supported (but I don't think it is), do not redirect me to web.config solutions.

like image 959
Steve B Avatar asked Jan 15 '19 13:01

Steve B


1 Answers

In Azure Storage Explorer, there is a property named CacheControl which you can find in any blob properties. If you set the CacheControl property with a value like max-age=100 as Fig 1 below, you can see it whether be enabled via browser debug tools like Chrome Chrome Developer Tools F12 as Fig 2 below.

Fig 1. Set the value of CacheControl property of a blob index.html enter image description here

Fig 2. Open Chrome Developer Tools to find my setting for index.html above enter image description here

So you can set cache control header for few blobs via Azure Storage Explorer, or do the same in programming for a large number of blobs, as the answer of SO thread Add Cache-Control and Expires headers to Azure Storage Blobs said.

like image 134
Peter Pan Avatar answered Oct 09 '22 08:10

Peter Pan