Posts

Showing posts with the label Javascript

YUI javascript compressor and PHP tags

YUI compressor is very useful and powerful tool for javascript files compression. Many developers compress their static javascript files but what about files with PHP tags? With something like this: var username = "<?php echo $username; ?>"; or like this function() { var some_code_before; <?php if (Acl::check("finance")) { ?> Ext.addShortcut('finance'); <?php } ?> var some_code_after; } First example will work, but YUI will throw an exception on second. And also this piece of javascript code does not pass validation. Lets wrap PHP tags into comments: function() { var some_code_before; /*<?php if (Acl::check("finance")) { ?>*/ Ext.addShortcut('finance'); /*<?php } ?>*/ var some_code_after; } Now this code is valid. But lets try to feed it to YUI: # yui test.js function(){var b;Ext.addShortcut("finance");var a}; PHP tags are stripped away by YUI and