For your last question, why ? I'll try to explain with what I know
A brief explanation of those three status codes in layman's terms.
- 200 - success (browser requests and get file from server)
If caching is enabled in the server
- 200 (from memory cache) - file found in browser, so browser is not going request from server
- 304 - browser request a file but it is rejected by server (ie, if the content is not modified since the last time it's requested)
For some files browser is deciding to request from server and for some it's deciding to read from stored (cached) files. Why is this ? Every files has an expiry date, so
If a file is not expired then the browser will use from cache (200 cache).
If file is expired, browser requests server for a file. Server check file in both places (browser and server). If same file found, server refuses the request. As per protocol browser uses existing file.
look at this nginx configuration
location / {
add_header Cache-Control must-revalidate;
expires 60;
etag on;
...
}
Here the expiry is set to 60 seconds, so all static files are cached for 60 seconds. So if u request a file again within 60 seconds browser will read from memory (200 memory). If u request after 60 seconds browser will request server (304).
I assumed that the file is not changed after 60 seconds, in that case you would get 200 (ie, updated file will be fetched from server).
So, if the servers are configured with different expiring and caching headers (policies), the status may differ.
In your case you are using cdn, the main purpose of cdn is high availability and fast delivery. Therefore they use multiple servers. Even though it seems like files are in same directory, cdn might use multiple servers to provide u content, if those servers have different configurations. Then these status can change. Hope it helps.
Added on 20/04/2023
For 304 to work we have to add If-Modified-Since header to the http request, if not server cannot check whether the content is modified or not.