Using YUI Compressor in JavaScript Files Containing PHP

I want to use YUI Compressor for JavaScript files containing PHP code, for example, for example:

<?php $include 'headerDefinitions.js.php'; ?>
function hello(name) {
    alert('Hello ' + name);
}
hello('<?= $_GET["name"] ?>');

This clearly causes some errors when working with the yui compressor as follows:

java -jar yui-compressor.jar --type js -o target-file.js.php source-file.js.php

because the compressor assumes that JavaScript is even part of PHP. Is there a way to compress JavaScript while saving and ignoring parts of PHP? So that the above example leads to the following:

<?php $include 'headerDefinitions.js.php'; ?>function hello(a){alert('Hello '+a)}hello('<?= $_GET["name"] ?>');
+1
source share
2 answers

To answer yourself:

jiggys JavaScript PHP, , , . . PHP JavaScript, ( ).

, YUI Compressor JavaScript, /*!, PHP- :

/*!
 <?php $include 'headerDefinitions.js.php'; ?> */
function hello(name) {
    alert('Hello ' + name);
}
hello('<?= $_GET["name"] ?>');

. , .

PHP- JavaScript , () :

var myString = '<?= $_GET["name"] ?>';

. , , PHP-.

0

. .js, PHP. , .js .

+3

Source: https://habr.com/ru/post/1725052/


All Articles