We have some PHP files that output JavaScript code. I know things could have been different, but that was a decision taken during the start of the project.
We have several PHP files which generate Javascript files, something like:
<?php Header("content-type: application/x-javascript");
if(strlen($_GET['country']) != 2){ exit;} //avoids code injection
include_once($_SERVER['DOCUMENT_ROOT'].'/countries/'.$_GET['country'].'.php');?>
/*Define GLOBAL Javascript variables*/
var COUNTRY = "<?php echo $GLOBALS["country"]; ?>";
/*Language code according to ISO_639-1 codes*/
var LANGUAGE = "<?php echo $lang_CT[$GLOBALS["country"]]; ?>";
...
What is the best way to minify that code a priori, i.e., not when the file is called or echoed, but on the server, using the Javascript minifying rules?
edit: I've been thinking and things might be complex to achieve, I imagine this case of invalid JS code:
var str = <?php echo "'a string';"; ?>
which outputs a valid JS code
var str = 'a string';
but basically I was wondering if there is any basic minifying option, to remove double spaces, comments and breaklines, which would then not affect the generated JS code.