← Back to release summary

Use specific fetch destination for JSON/CSS modules

Category
JavaScript
Type
Chromium catches up
Status
In development (Chrome In development)
Intent stage
None

WPT details: - https://wpt.fyi/results/fetch/api/request/destination/fetch-destination.https.html - https://wpt.fyi/results/content-security-policy/connect-src/connect-src-json-import-allowed.sub.html - https://wpt.fyi/results/content-security-policy/connect-src/connect-src-json-import-blocked.sub.html - https://wpt.fyi/results/content-security-policy/style-src/import-style-allowed.sub.html - https://wpt.fyi/results/content-security-policy/style-src/import-style-blocked.sub.html

Summary

CSS and JSON modules will be fetched using a specific fetch destination (either "css" or "json") rather than a generic "script", that is normally used for JavaScript modules. This has the following effects: - the `Accept` HTTP header in the request will describe the expected mime type (`text/css,*/*;q=0.1` or `application/json,*/*;q=0.5`) - those modules will respect the style-src or connect-src Content Security Policies, rather than using JavaScript's script-src - When inspecting the request's destination (either through a service worker or through the `Sec-Fetch-Destination` HTTP header) it will be reported as `"style"` or `"json"`, rather than empty.

Motivation

Currently, browsers throw an error if a server provides a non-JSON/CSS file in response to a JSON/CSS module import. However, there is no way for the browser to distinguish between requests for JavaScript modules and JSON/CSS modules even though in most other parts of the web platform this is done through the Accept HTTP header. In addition to that, JSON/CSS modules were fetched without respecting the relevant CSPs for JSON and CSS resources, but instead using the CSP defined for JavaScript resources.

Standards & signals

Ecosystem

View on chromestatus.com