有没有一个插件可以自动压缩和缓存 JavaScript?

发布于 2024-11-23 18:14:09 字数 273 浏览 2 评论 0原文

我正准备开始一个新项目,我想知道是否有一种方法可以在服务器端自动缩小 JavaScript,并在 JavaScript 缩小一次后提供缓存?我可以简单地编写一个构建脚本来完成此任务,但如果我可以“一劳永逸”,可以自动缩小,那就太好了。在这种情况下,推荐的路线是什么?我应该在 JavaScript 上线之前以时间为代价缩小它,还是应该寻找一些可以在服务器端自动为我完成此操作的东西?

编辑

我可能会使用 Django,但是当然,JavaScript 和媒体与实际的“HTML”/应用程序输出分开提供。

I'm getting ready to start on a new project and I'd like to know if there's a way to automatically minify JavaScript on the server side, providing caching once the JavaScript has been minified once already? I could simply write a build script to accomplish this, but it'd be nice if I could "fire-and-forget" so to speak, with automatic minification. What would be the recommended route in this scenario? Should I minify my JavaScript before it goes online at the cost of time or should I look for something that'll automatically do it for me on the serverside?

EDIT

I'll probably be using Django, but of course, JavaScript and media is served separately from the actual "HTML"/application output.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

沩ん囻菔务 2024-11-30 18:14:09

这完全取决于您使用的服务器端语言。它与 Javascript 或 Css 没有(太多)关系,而是与 PHP、.NET、Ruby 等相关

注意:这些只是我所做的一些快速搜索。我没有任何经验与其中任何一个。)

我个人建议不要在运行时进行任何的缩小/组合,因为服务器端性能会反复发生并且再次

上面是我的“答案”


下面是我的“偏好”

我的偏好是使用某种构建时间缩小/组合工具,该工具可以一次实现目标,然后让服务器仅“服务”。

由于我在 IDE 中运行 Visual Studio,因此我更喜欢使用名为 Chirpy 的工具...最终结果是一个静态 site.min.js 文件和一个静态 site.min.css 文件,其中包含我需要的一切。我将不再因在运行时组合/缩小我的 js/css 而遭受性能损失。


编辑

请务必阅读下面的评论,因为它们有助于添加 OP 正在寻找的整体概念。


编辑

还刚刚发现 WebPutty,看起来像一个非常灵活的工具。

This will all depend on what server side language you're using. It will have nothing (so much) to do with Javascript or Css, but rather PHP, .NET, Ruby, etc.

(note: these are just some quick searches I've done. I don't have any experience with any of them.)

I personally recommend NOT doing ANY of the minification / combining at run time since there is a server side performance hit that happens over and over and over again.

Above is my "Answer"


Below is my "Preference"

My preference is to use some sort of a Build Time minification / combining tool that achieves the goal once and leaves the server to just "serve".

Since I'm running Visual Studio for my IDE, my preference is to use a tool called Chirpy... the end result is a single static site.min.js file and a single static site.min.css file that has everything I need. I will no longer suffer a performance hit from combining/minifying my js/css at run time.


Edit

Be sure to read the comments below, as they help add to the overall concept of what the OP is looking for.


Edit

Also just found WebPutty, looks like a pretty slick tool.

萌面超妹 2024-11-30 18:14:09

YUI Compressor 对我来说效果非常好,需要在服务器上安装 Java,并且您向其传递正确的参数:

这是我使用的构建脚本(用 Ruby 编写,但不是必须的),它使用正确的参数调用压缩器,这就是它所做的一切。

#
# Build JS Files
#
require 'rake/packagetask'

JAVA = 'java'
OUTPUT = 'public/js/sitel-core.js'
MINOUTPUT = 'public/js/sitel-core.min.js'
OUTCSS = 'public/css/styles.css'
MINCSS = 'public/css/styles.min.css'
WIZOUT = 'public/js/sitel-wizard.js'
WIZMIN = 'public/js/sitel-wizard.min.js'

desc "Build CSS Scripts"
task :buildcss do
    files = 'public/css/styles.css'
    `#{JAVA} -jar build/yuicompressor.jar #{OUTCSS} -o #{MINCSS}`
end

desc "Build JS Scripts"
task :build => [:buildcss] do
    files = 'public/js/sitel.js public/js/sitel/popup.js public/js/microtable.js public/js/microbox.js public/js/sitel/popup.page.js public/js/sitel/flexigrid.js public/js/flexigrid/flexigrid.js public/js/nyroModal-1.6.2/js/jquery.nyroModal-1.6.2.js public/js/help-bubble.js public/js/sitel/elgg.js'
    `cat #{files} > #{OUTPUT}`
    `#{JAVA} -jar build/yuicompressor.jar #{OUTPUT} -o #{MINOUTPUT}`    

    wizard = 'public/js/wizard2.js public/js/dual-select.js public/js/filterbox.js public/js/jquery-validate/jquery.validate.js public/js/smartsearch.js public/js/smartsearch-validator.js public/js/flexigrid/flexigrid_helper.js '
    `cat #{wizard} > #{WIZOUT}`
    `#{JAVA} -jar build/yuicompressor.jar #{WIZOUT} -o #{WIZMIN}`
end

desc "Build JS Scripts"
task :default => :build

YUI Compressor works amazingly for me, requires Java on the server and you passing it the right params:

Here is my build script I use (written in Ruby, but does not have to), it calls the compressor with the right params, thats all it does.

#
# Build JS Files
#
require 'rake/packagetask'

JAVA = 'java'
OUTPUT = 'public/js/sitel-core.js'
MINOUTPUT = 'public/js/sitel-core.min.js'
OUTCSS = 'public/css/styles.css'
MINCSS = 'public/css/styles.min.css'
WIZOUT = 'public/js/sitel-wizard.js'
WIZMIN = 'public/js/sitel-wizard.min.js'

desc "Build CSS Scripts"
task :buildcss do
    files = 'public/css/styles.css'
    `#{JAVA} -jar build/yuicompressor.jar #{OUTCSS} -o #{MINCSS}`
end

desc "Build JS Scripts"
task :build => [:buildcss] do
    files = 'public/js/sitel.js public/js/sitel/popup.js public/js/microtable.js public/js/microbox.js public/js/sitel/popup.page.js public/js/sitel/flexigrid.js public/js/flexigrid/flexigrid.js public/js/nyroModal-1.6.2/js/jquery.nyroModal-1.6.2.js public/js/help-bubble.js public/js/sitel/elgg.js'
    `cat #{files} > #{OUTPUT}`
    `#{JAVA} -jar build/yuicompressor.jar #{OUTPUT} -o #{MINOUTPUT}`    

    wizard = 'public/js/wizard2.js public/js/dual-select.js public/js/filterbox.js public/js/jquery-validate/jquery.validate.js public/js/smartsearch.js public/js/smartsearch-validator.js public/js/flexigrid/flexigrid_helper.js '
    `cat #{wizard} > #{WIZOUT}`
    `#{JAVA} -jar build/yuicompressor.jar #{WIZOUT} -o #{WIZMIN}`
end

desc "Build JS Scripts"
task :default => :build
陌生 2024-11-30 18:14:09

如果您使用 Apache,您可以使用此解决方案来动态提供缩小的 js 文件:
https ://www.unixmen.com/how-to-auto-minify-javascript-files-on-page-load-in-apache-using-uglifyjs/

If you use Apache you can use this solution that serve minified js files on the fly :
https://www.unixmen.com/how-to-auto-minify-javascript-files-on-page-load-in-apache-using-uglifyjs/

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文