简体   繁体   English

JSP-内联JS压缩/压缩

[英]JSP - Inline JS Compression / Minification

We have an web application written in Java which has around 150 JSP files. 我们有一个用Java编写的Web应用程序,其中包含大约150个JSP文件。 Unfortunately, each of these JSP files contains inline JS code written in it. 不幸的是,每个这些JSP文件都包含编写的内联JS代码。 I'm trying to compress these file to improve the performance. 我正在尝试压缩这些文件以提高性能。

Currently I'm using HTMLCompressor which just compresses the HTML part of the file, but doesn't minify the scripts written inline. 目前,我正在使用HTMLCompressor,它仅压缩文件的HTML部分,但不会缩小内联编写的脚本。 Though the HTMLCompressor provides an option to compress the inline scripts also, it fails to handle the JSP condition tags written within my script tag. 尽管HTMLCompressor也提供了压缩内联脚本的选项,但它无法处理写在我的脚本标记中的JSP条件标记。 I tried changing the compressor from YUI to Google Closure, but the problem remains as is. 我尝试将压缩机从YUI更改为Google Closure,但问题仍然存在。

Is there is a way to handle this scenario or kindly suggest if there are any other compression tools which lets me compress the JSP/HTML along with the inline scripts written in this. 有没有一种方法可以处理这种情况,或者是否建议使用任何其他压缩工具来压缩JSP / HTML以及由此编写的内联脚本。

Note: Moving scripts to separate JS file is one of the optimization I can think as of now, however this is not an option for me since the number of JSP files are huge and time is an constraint. 注意:到目前为止,我可以想到将脚本移动到单独的JS文件是一种优化,但是这对我来说不是一个选择,因为JSP文件的数量很大并且时间是一个约束。

Please feel free to correct if my thought process itself is wrong. 如果我的思考过程本身有误,请随时纠正。

If your pages aren't using a strict CSP banning eval. 如果您的网页没有使用严格的CSP禁止评估。 One solution would be to wrap your expressions in evals: 一种解决方案是将表达式包装成eval:

var x = eval("... JSP substitution here ... "); var x = eval(“ ...此处的JSP替换...”);

Depending on what you are providing the pages, this may work but as you can provide any arbitrary text it is easy to envision cases where this won't work. 根据您提供页面的内容,这可能会起作用,但是由于您可以提供任意文本,因此很容易想到这种情况不起作用的情况。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM