So, I'm trying to use PHP in a .js file, that's what I still have.
.htaccess (any * .api.js will be processed as PHP)
<FilesMatch "^.*?api.*?$">
SetHandler php54-script
</FilesMatch>
map.api.js
<?php
header("Content-type: application/javascript");
?>
.php files include
<script type="text/javascript" src="map.api.js"></script>
For some reason this does not work, and after much research, I cannot find a solution.
In the developer’s chrome tools, I get an error message Uncaught SyntaxError: Unexpected token <- quite understandably, he does not expect <?phpat the top of the file map.api.js.
Has anyone else tried using PHP in a .js file before? If there is a better solution I would like to know, since I cannot find much on Google.
source
share