Caching directives for index.html is ignored

Brian Pedersen 31 Reputation points
2022-02-15T10:49:01.807+00:00

I know this is a duplicate of https://learn.microsoft.com/en-us/answers/questions/731947/caching-directives-for-indexhtml-is-ignored.html, but it we rather urgently need support on how to work around this.

We are running a React SPA in static web apps, and want to disable caching of the index.html file.

We have added a staticwebapp.config.json file, and we can apply a no-cache directive using wildcards. But it doesn't work for specific files.

Working (but applies to all files):

 {  
   "routes": [  
     {  
       "route": "/*",  
       "headers": {  
         "cache-control": "no-cache"  
       }  
     }  
   ]  
 }  

Not working:

 {  
   "routes": [  
     {  
       "route": "/index.html",  
       "headers": {  
         "cache-control": "no-cache"  
       }  
     }  
   ]  
 }  

The documentation states that "When protecting a route that serves a file, always use the full path of the file such as /profile/index.html."

We obviously don't want to disable caching for every single file in the app, so I need a way to indicate the specific file.

We have verified that the staticwebapp.config.json is being used, as it works with a wildcard. The problem is specifically about pointing to /index.html

Azure Static Web Apps
Azure Static Web Apps
An Azure service that provides streamlined full-stack web app development.
782 questions
0 comments No comments
{count} votes

1 additional answer

Sort by: Most helpful
  1. Brian Pedersen 31 Reputation points
    2022-02-15T11:37:27.227+00:00

    I managed to find a workaround, as we only have a single html file, I can target it with a wildcard, which works. {

        "routes": [
          {
            "route": "/*.html",
            "headers": {
              "cache-control": "no-cache"
            }
          }
        ]
      }
    
    0 comments No comments