0
votes

During security check, its reported that "The Content-Type HTTP header is missing charset attribute" is missing for js and css file.

Please check below screenshot:

enter image description here

My HTML Was look like below before i have added the charset

<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8">
        <script type="text/javascript" src="/backend/web/assets/3faf0a44/jquery.js"></script>
    </head>
</html>

Then i have added the charset="UTF-8" in

<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8">
        <script type="text/javascript" src="/backend/web/assets/3faf0a44/jquery.js" charset="UTF-8"></script>
    </head>
</html>

Still Charset is not added in Response Header, Please check below screenshot:

enter image description here

So what should i do so my Content-Type header changed to below:

content-type: application/javascript; charset=utf-8

2
This will need to be done in the web server configuration. Which web server are you using? - puhlen
Apache Web Server - DS9

2 Answers

2
votes

Let me try to answer, you can do that by editing apache2.conf (for Debian like OS(es) ) or httpd.conf ( CentOS like OS(es) ) and add following lines:

#Set the correct Char set so don't need to set it per page.
AddDefaultCharset utf-8
#for css, js, etc.
AddCharset utf-8 .htm .html .js .css

Source:

0
votes

So the reason adding it to the html doesn't work is that doesn't tell the server anything, that only tells the browser latter on when it goes to parse the file after downloading and only if it decides to parse meta tags. (which the major ones do)

but if you want to send data as part of the http header and your using php to serve up the page/site/file then you cause the header() command, what you put in there will be appended on to the http header. you can use this command more then once to add in new bits. but you must put all calls to this function before anything that outputs data. as once php has to output something it'll compile and send the header at that point along with the output and so no further changes to it can be made.

so try this at the top of the file

<?php
 header('charset=UTF-8');
?>

I think that'll do what you want.