有没有一个插件可以自动压缩和缓存 JavaScript?
我正准备开始一个新项目,我想知道是否有一种方法可以在服务器端自动缩小 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这完全取决于您使用的服务器端语言。它与 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 staticsite.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.
YUI Compressor 对我来说效果非常好,需要在服务器上安装 Java,并且您向其传递正确的参数:
这是我使用的构建脚本(用 Ruby 编写,但不是必须的),它使用正确的参数调用压缩器,这就是它所做的一切。
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.
如果您使用 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/