4

I want to set Cache-Control: no-cache for my index.html, as recommended in docs.

For my js chunks, I can locate them in my dev tools' network tab and see the headers there:
cache-control header visible in network tab

But my index.html is not present in the network tab:
no results given for "index" search in network tab

Why is that? And how can I make sure it has the Cache-Control: no-cache header on it?

I can see index in sources tab
enter image description here

The app is served by production server (not by CRA dev server), and CRA service worker is disabled.

Michal Kurz
  • 1,592
  • 13
  • 41
  • 1
    You're searching for resources with `index` in them in your browser tools. Are you including `index.html` in the URL that you load? Or fetching it by directory, and having that file served by default? – Joe Nov 30 '20 at 12:39
  • Its the index that loads the rest. How come do you want to see index in the network call ? – juxhin bleta Dec 01 '20 at 13:04
  • @Joe : It's CRA single-page app, so It should be included with in response to all urls. – Michal Kurz Dec 01 '20 at 16:46
  • 1
    @juxhinbleta Yes, Index loads the rest of the resources. But first, it has to be laoded itself. I don't really understand the question. – Michal Kurz Dec 01 '20 at 16:47

2 Answers2

1

If I got you right, you want to turn off the server's caching for index.html.

There are many ways to do this. Here are some configurations you can do on the server-side.

NGINX: (nginx.conf)

location / {
    gzip_static on;
    try_files $uri @index;
}

location @index {
    add_header Cache-Control no-cache;
    expires 0;
    try_files /index.html =404;
}

IIS: (web.config)

<?xml version="1.0" encoding="UTF-8"?>
<configuration>    
  <location path="index.html">
    <system.webServer>
      <httpProtocol>
        <customHeaders>
          <add name="Cache-Control" value="no-cache" />
        </customHeaders>
      </httpProtocol>
    </system.webServer>
  </location>    
</configuration>

or you can use html meta tag configuration.

Necip Sunmaz
  • 1,546
  • 17
  • 22
  • I know that. I already attempted to set cache-control. I now want to test if it is set correctly. That is why I want to locat index.html in my network tab – Michal Kurz Dec 01 '20 at 16:41
  • 1
    If you don't see index.html in your console, probably your domain name is your index.html. This is because index.html configured "default page" on the server. Please check how to work URL Rewrite engine on the server. – Necip Sunmaz Dec 02 '20 at 06:30
1

The reason I don't see a request labeled "index" in the network tab is because I am not requesting index.html directly, I get it as a response when requesting a specific in-app url. I can find the respective request in devtools network tab under current URL, and it has text/html in the type column.

Michal Kurz
  • 1,592
  • 13
  • 41