[英]Compress embedded Javascript in HTML markup
If you have a separate .js
file, you may simply compress it with tools such as Yahoo YUI Compressor. 如果您有单独的
.js
文件,则可以使用Yahoo YUI Compressor之类的工具简单地对其进行压缩。
But, how can I compress embedded Javascript in every pages in my project? 但是,如何在项目的每个页面中压缩嵌入式Javascript?
(Copying the Javascript to a separate file, then compress, and then copy back to my page cannot be a professional solution for obvious reasons for a medium or big project) (出于明显的原因,对于中型或大型项目,将Javascript复制到一个单独的文件,然后进行压缩,然后再复制回我的页面,这不是一个专业的解决方案)
You would normally have a build process which turns the source into a deployable form. 通常,您将具有一个将源转换为可部署形式的构建过程。 This would include any compilation, unit tests, compression etc.
这将包括任何编译,单元测试,压缩等。
YUI compressor has a build tool for just that http://yuilibrary.com/download/builder/ YUI压缩器仅具有http://yuilibrary.com/download/builder/的构建工具
Also check out ANT http://ant.apache.org/ 另请查看ANT http://ant.apache.org/
You could run a backend process that parses your html files, extracts the javascript code and inserts the compressed one. 您可以运行一个后端程序,该程序分析您的html文件,提取javascript代码并插入压缩的代码。 But in any case I would recommend you to seperate all your js into js files.
但无论如何,我建议您将所有js分成js文件。 This is it will be easier for you to maintenance in the future.
这样一来,将来您将更容易维护。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.