开发者

Minify JavaScript code in a JSPX page (in a Spring MVC WebApp)

开发者 https://www.devze.com 2023-03-19 03:06 出处:网络
So, I have a jspx page which has JS code in it, and part of the code is generated dynamically, so I can\'t minify and paste the minified code.

So, I have a jspx page which has JS code in it, and part of the code is generated dynamically, so I can't minify and paste the minified code.

E.g. Let's imagine I draw a chart with Google Chart API, and the I fill the data with a forEach JSTL tag.

<script type="text/javascript">
    google.load('visualization', '1', {'packages':['corechart']});
    google.setOnLoadCallback(drawChart);

    function drawChart() {
        var data = new google.visualization.Dat开发者_JAVA技巧aTable();
        data.addColumn('number', 'data');
        data.addRows(${fn:length(chartData)});
        <c:forEach items="${chartData}" var="entry" varStatus="status">
           data.setValue(${status.count-1},0,${entry.value});
        </c:forEach>      
        var chart = new google.visualization.LineChart(document.getElementById('google_chart'));
        chart.draw(data, {width: 620, height: 300});    
    }
</script>  

My ideal solution would be for there to exist a tag e.g. <something:minify><script type="text/javascript"> .... </script></something:minify> which would do the job, but I'm interested in all possible solutions.


UglifyJS can be used to minify code on-the-fly.
It's loosly based on Google Closure but is a lot faster and succeeds in some cases where Closure doesn't.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号