What is an appropriate content-type header for JavaScript files

0 votes
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?
Jul 7, 2020 in Java-Script by kartik
• 37,520 points
311 views

1 answer to this question.

0 votes

Hello @kartik,

JS has two registered MIME types:

 The obsolete text/javascript and the now official application/javascript.

Thus, use application/javascript. You can configure your server to always serve application/javascript in the HTTP headers; browsers that don't support it also pay no attention to the actual content-type.

Hope it helps!!

Thank You!!

answered Jul 7, 2020 by Niroj
• 82,760 points

Related Questions In Java-Script

0 votes
1 answer

Which is best window.location (JS) vs header() (PHP) for redirection?

Hello @kartik, It depends on how and when ...READ MORE

answered Jul 7, 2020 in Java-Script by Niroj
• 82,760 points
1,906 views
0 votes
1 answer

How do I test for an empty JavaScript object?

Hello @kartik, Try this: var obj = {}; return Object.keys(obj).length; Hope ...READ MORE

answered Aug 28, 2020 in Java-Script by Niroj
• 82,760 points
93 views
0 votes
1 answer

What is the “hasClass” function with plain JavaScript?

Hello @Kartik, Simply use classList.contains(): if (document.body.classList.contains('thatClass')) { ...READ MORE

answered Sep 2, 2020 in Java-Script by Niroj
• 82,760 points
135 views
0 votes
1 answer

How can I determine the type of an HTML element in JavaScript?

Hello @kartik, nodeName is the attribute you are looking ...READ MORE

answered Oct 8, 2020 in Java-Script by Niroj
• 82,760 points
217 views
0 votes
1 answer

How can we Create Multiple Where Clause Query Using Laravel Eloquent?

Hii, You can use Conditions using Array: $users = User::where([ ...READ MORE

answered Mar 30, 2020 in Laravel by Niroj
• 82,760 points
7,976 views
0 votes
1 answer

How to send email using php?

Hello @kartik 1.) Download PHPMailer, open the zip file ...READ MORE

answered Apr 1, 2020 in PHP by Niroj
• 82,760 points
274 views
0 votes
1 answer

Where to register Facades & Service Providers in Lumen?

Hello, To register a facade with an alias, ...READ MORE

answered Apr 6, 2020 in Laravel by Niroj
• 82,760 points
1,510 views
0 votes
1 answer

How can I update NodeJS and NPM to the next versions?

Hello @kartik, First check your NPM version npm -v 1).Update ...READ MORE

answered May 5, 2020 in Java-Script by Niroj
• 82,760 points
168 views
0 votes
1 answer

What is callback function in JavaScript?

callback is not a keyword, its just ...READ MORE

answered Jan 30, 2020 in Java-Script by Niroj
• 82,760 points
4,767 views