如何使用JSP标记缩小内联JavaScript函数?

时间:2014-03-19 08:57:01

标签: javascript jsp yui minify

在此JSP片段文件中,第二个内联块正确缩小。但是当使用压缩时,第一个块是完全空的。我发现只要内联JavaScript包含函数声明就会发生这种情况。有没有办法缩小这些函数声明而不需要将它们放入外部.js?

<%@page contentType="text/html" pageEncoding="UTF-8" trimDirectiveWhitespaces="true"%>
<%@ taglib uri="http://htmlcompressor.googlecode.com/taglib/compressor" prefix="compress" %>
<script>
   //This results in empty output:  
   <compress:js enabled="true" yuiJsLineBreak="80">
    $(document).ready(function() {
        //This is not executed
        console.log("Document ready fired " + $().jquery);
    });
    function tester(message) {
        console.log(message);
        return 0;
    }
    </compress:js>
</script>

<script>
    // This is working perfectly: 
    <compress:js enabled="true" yuiJsLineBreak="80">
    //Some comment that should not be shown
    console.log("Minified code did something...");
    console.log("...");
    var a = 1 + 4;
    $().jquery;
    $(document).ready();
    </compress:js>
</script>

0 个答案:

没有答案