自动缩减上传的CSS和Javascript [英] Automagically Minify CSS and Javascript on Upload

查看:149
本文介绍了自动缩减上传的CSS和Javascript的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有人知道在上传时通过处理脚本自动运行某些文件类型的好方法?我试图完成自动缩小CSS和Javascript当我上传到服务器,保持一个漂亮的,人们可读的版本在本地端,同时保持一个缩略词在服务器上。我目前在Windows上使用WinSCP,这在一定程度上是可脚本化的,但可能不够足够脚本。我可能需要一些拼凑在一起的解决方案,所以不要害怕用胶带建议一些东西;然而,我确实需要在我的本地计算机上做缩小,并上传被压缩的文件,因为我使用共享主机,无法在服务器上安装垃圾。



谢谢。

解决方案

我建议创建一个makefile来解决这个特殊的问题,这里是一个快速和脏的makefile我用于一个网站的:

  PUBDIR = .. / .. / static / js / 
OUTDIR =。/ build /
COMPRESSOR = .. / yui / build / yuicompressor-2.4.2.jar
ARGS =
VPATH = $ {OUTDIR}
INST_TARGETS = $ {OUTDIR} jgblue.js

jgblue.js:combined.js
java -jar $ {COMPRESSOR} $ {ARGS} $ {OUTDIR} $< -o $ {OUTDIR} $ @

combine.js:main.js listview.js tabs.js
cat $ ^> $ {OUTDIR} $ @

.PHONY:install

安装:
cp $ {INST_TARGETS} $ {PUBDIR}
 <$ c $> 

c> make&& make install

首先它需要所有的开发文件,并将它们连接成一个文件,文件将被压缩并复制到您的公共目录中。我使用 YUICompressor 进行压缩,效果非​​常好。


Does anyone know of a good way to automatically run certain file types through a processing script on upload? I'm trying to accomplish automatically minifying CSS and Javascript when I upload them to the server, keeping a nice, human-readable version on the local side while keeping a minified one on the server. I'm currently using WinSCP on Windows, which is scriptable to some degree but might not be scriptable enough. I'd probably need some kind of cobbled-together solution, so don't be afraid to suggest something with duct tape in it; however, I do need to do the minification on my local computer and upload the squished file, since I use shared hosting and can't install junk on the server.

Thanks.

解决方案

I recommend creating a makefile to solve this particular problem, here's a quick and dirty makefile I'm using for a site of mine:

PUBDIR=../../static/js/
OUTDIR=./build/
COMPRESSOR=../yui/build/yuicompressor-2.4.2.jar
ARGS=
VPATH=${OUTDIR}
INST_TARGETS=${OUTDIR}jgblue.js

jgblue.js: combined.js
    java -jar ${COMPRESSOR} ${ARGS} ${OUTDIR}$< -o ${OUTDIR}$@

combined.js: main.js listview.js tabs.js
    cat $^ > ${OUTDIR}$@

.PHONY: install

install:
    cp ${INST_TARGETS} ${PUBDIR}

Then all you have to type is:

make && make install

First it takes all of your development files and concatenates them into a single file, then the concatenated file gets compressed and copied into your public directory. I'm using YUICompressor for compression, it works quite well.

这篇关于自动缩减上传的CSS和Javascript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆