The internet is full of answers to the question of "how to force the browser to download a file".
This is a small app to test combinations of file types, download attribute and the Content-Disposition header.
npm i && npm start- Browse to
http://localhost:8080
- When the asset is in the same origin the
downloadattribute is respected regardless of file type. - When the asset is not in the same origin, the
downloadattribute is ignored for files that type browser can display (in this case .txt, .png, .log, but not .zip) - #2 applies even when there is a redirect from the same origin to another one (i.e. in the case of redirecting to a CDN)
Content-Disposition: attachmentheader seems to force the browser to download all files when thedownloadattribute is not present!
For Chrome 72, but might apply to other browsers as well, the best way to get the browser to force download a file is by using the Content-Disposition header.
If the file is under the same origin, but without redirects, the download attribute will work as well