I am using php to bundle javascript and CSS files.
...
$js_files = ['path/to/script.js', 'path/to/jquery.js'];
header( "Content-type: application/javascript" );
foreach($js_files as $path){
echo file_get_contents($path);
}
...
But when I add them to my HTML page:
<script src="http://localhost:63342/project/assets/assets.php"></script>
it gives me syntax error Uncaught SyntaxError: illegal character U+0001
...function(){
S.event.add(this�Yÿø��, t, i, r, n)
}...
�Yÿø�� is an illegal string, but my original code is correct:
...function(){
S.event.add(this, t, i, r, n)
}...
also tried readfile() and mb_convert_encoding() for encoding but still not working!
Manually it's working correctly:
<script src="http://localhost:63342/project/assets/jQuery/jquery.3.6.js"></script>
You can set the header like that:
header('Content-Type: text/html; charset=utf-8');
to avoid the problem.