简体   繁体   English

压缩HTML标记中的嵌入式Javascript

[英]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.

相关问题 如何压缩 HTML/JAVASCRIPT/CSS 网页以与在嵌入式设备上运行的 Web 服务器一起使用? - How do I compress an HTML/JAVASCRIPT/CSS web page to be used with a web server running on an embedded device? ASP.NET MVC 3:帮助将 JavaScript 链接转入嵌入式/压缩 html 标记? - ASP.NET MVC 3: Helper to turn JavaScript link in to embedded / compressed html markup? 如何压缩/缩小嵌入了php的javascript - how to compress / minify javascript that has embedded php 带有javascript函数的HTML短语标记 - HTML phrase markup with javascript function HTML 标记在 Javascript 中使用 for 循环是否比正常的 HTML 标记慢? - Is HTML Markup using for loop in Javascript slower then just normal HTML markup? 如何使用正则表达式 javascript 将带有自定义标记的评论解析为 html 标记 - How parse a comment with custom markup to html markup using regex javascript HTML中嵌入的Javascript无法加载 - Javascript embedded in html not loading 嵌入式JavaScript和HTML中的安全性 - Security in embedded javascript and HTML HTML内嵌的JavaScript - javascript embedded inside html 如何压缩Javascript中的HTML标签映射脚本? - How to compress HTML tags mapping script in Javascript?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM