Given a JSON API endpoint /api/config
, we're trying to use <link rel="prefetch" href="/api/config">
in the head of an HTML document. Chrome downloads the data as expected when it hits the link tag in the HTML, but requests it again via XHR from our script about a second later.
The server is configured to allow caching, and is responding with Cache-Control: "max-age=3600, must-revalidate"
in the header. When Chrome requests the data again, the server responds correctly with a 304 Not Modified status.
The use case is this: the config endpoint will always be requested from the Javascript in our single page application using XHR (an AngularJS resolve, in case it's relevant). However, our scripts are very large and take a long time to parse, so the JSON config will not be requested until the parsing is finished. Prefetching would allow us to use some of that parsing time to fetch and cache responses from API endpoints that would otherwise have to wait for the scripts to load.