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.
893 questions
0 comments No comments
{count} votes

Accepted answer
  1. Ryan Hill 27,686 Reputation points Microsoft Employee
    2022-02-16T23:55:16.957+00:00

    Hi @Brian Pedersen , I believe you posted the same question in which I responded, so posting here as well. This is a known issue that will be address in an upcoming update. I would estimate it could rollout within in the next month or so.

    0 comments No comments

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

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.