What is an appropriate content-type header for JavaScript files?
http, javascript, php
Solution
According to the IANA Registered MIME media type list, JS has two registered MIME types; the obsolete `application/javascript` and the now official `text/javascript`.
Thus, use `text/javascript`.
Note: This answer previously claimed the exact opposite (based on RFC 4329), but since RFC 9239 was published in May 2022 the `text/javascript` media type is preferred over `application/javascript`.
Problem
I am delivering a JS response from a PHP file. When setting the `Content-Type` header which value should I use, `application/javascript` or `text/javascript`? What’s the difference between the two?