简体   繁体   English

如何组织和缩小大量的javascript文件?

[英]How to organize and minify lots of javascript files?

I have a project written on PHP and JavaScript. 我有一个用PHP和JavaScript编写的项目。

For example, I have two main JavaScript files main1.js and main2.js. 例如,我有两个主要的JavaScript文件main1.js和main2.js。

They use the same functions, and I want to extract the functions to lib.js etc. 它们使用相同的功能,我想将这些功能提取到lib.js等中。

On develop environment it's more useful to use 3 different files, but on production i'd like to have 2 minifyied files with lib.js included. 在开发环境中,使用3个不同的文件更为有用,但是在生产环境中,我希望包含2个包含lib.js的缩小文件。

I want to see changes on dev immediately without any preprocessing, and I want to use some preprocessing on production. 我想在没有任何预处理的情况下立即查看对dev的更改,并且我想在生产中使用一些预处理。

For example I can write a javascript function require(filename) that loads needed js file, but how to tell minifyer to include the file inline on production? 例如,我可以编写一个JavaScript函数require(filename)来加载所需的js文件,但是如何告诉minifyer在生产中内联该文件呢?

You should look into YUI Compressor 你应该看看YUI Compressor

and also into creating makefiles 以及创建makefiles

you can also compress CSS with YUI Compressor 您还可以使用YUI Compressor压缩CSS

If you are using netbeans then you can use the plugin from here 如果您使用的是netbeans,则可以从此处使用插件

Plugin 插入

Also you can use 你也可以用

minifycss minifycss

YUI YUI

For online compression 用于在线压缩

Coffee Script is used for caching the js files on browser side. Coffee Script用于在浏览器端缓存js文件。 It create a single js file from all files, and minify the resultant code. 它从所有文件创建一个js文件,并缩小结果代码。

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

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