javascript - CDN上如何 解决实现 JS/CSS自动压缩方案?(通过 JSMinify)
需求说明
网站 www.xxx.com,环境WIN64 WAMP,分布3太服务器,主1台,次3台。里面用到的图片/CSS/JS 都放在 www.xxx.com/Public/ 目录下。需求是网站中引入到的/Public 目录下的JS/CSS 都会自动压缩,利于打开速度。
原方案
通过JSMInify + htaccess,把访问 /Public 目录中的JS/CSS 的请求地址指向 JSMinify 中的PHP ,然后通过JSMinify包进行自动压缩。这样程序员和设计上传CSS JS就无需做任何操作。很方便。
需求变更
先要求将 /Public 中的资源全部转移到CDN 服务器。CDN服务器配置 LN(Linux + Nignx),不支持PHP 不支持 htaccess。如何将工作量做到最小?
个人方案
<code>1)每次上传Public 中的CSS/JS 先试用Notepad++ 中的JSMini插件进行压缩格式化。然后再传 不足:网站仍旧大改动中,每次都可能修改很多JS CSS,如果一个个压缩,很可能遗漏或者有些错误。 2)自己试用JSMinify 制作一个插件,扫描指定目录中的JS/CSS 文件,然后压缩后存放。 不足:仍旧是需要手动操作,且制作这个插件需要花费一定时间。 3)寻找网络上的批量压缩工具 问题:目前没有找到。 </code>
连接
<code>Google JSMinfiy:https://code.google.com/p/minify/ </code>
如何才可以简化?
我现在使用的方案是自己本地用PHP建立一个脚本,将Public 目录的 资源(非CSS/JS)全都复制到另外一个目录,CSS/JS 就采用 http://localhost/min/index.php?filename=$filename 的方式下载保存。有点简单粗暴,但是省略了在minify类库上创建程序的麻烦。
回复内容:
需求说明
网站 www.xxx.com,环境WIN64 WAMP,分布3太服务器,主1台,次3台。里面用到的图片/CSS/JS 都放在 www.xxx.com/Public/ 目录下。需求是网站中引入到的/Public 目录下的JS/CSS 都会自动压缩,利于打开速度。
原方案
通过JSMInify + htaccess,把访问 /Public 目录中的JS/CSS 的请求地址指向 JSMinify 中的PHP ,然后通过JSMinify包进行自动压缩。这样程序员和设计上传CSS JS就无需做任何操作。很方便。
需求变更
先要求将 /Public 中的资源全部转移到CDN 服务器。CDN服务器配置 LN(Linux + Nignx),不支持PHP 不支持 htaccess。如何将工作量做到最小?
个人方案
<code>1)每次上传Public 中的CSS/JS 先试用Notepad++ 中的JSMini插件进行压缩格式化。然后再传 不足:网站仍旧大改动中,每次都可能修改很多JS CSS,如果一个个压缩,很可能遗漏或者有些错误。 2)自己试用JSMinify 制作一个插件,扫描指定目录中的JS/CSS 文件,然后压缩后存放。 不足:仍旧是需要手动操作,且制作这个插件需要花费一定时间。 3)寻找网络上的批量压缩工具 问题:目前没有找到。 </code>
连接
<code>Google JSMinfiy:https://code.google.com/p/minify/ </code>
如何才可以简化?
我现在使用的方案是自己本地用PHP建立一个脚本,将Public 目录的 资源(非CSS/JS)全都复制到另外一个目录,CSS/JS 就采用 http://localhost/min/index.php?filename=$filename 的方式下载保存。有点简单粗暴,但是省略了在minify类库上创建程序的麻烦。
为什么不用grunt或者gulp实现自动化压缩
CDN 可以做镜像备份吗?资源还放在源站上,请求去请求 CDN,CDN 上面没有资源的话,让 CDN 去源站同步。做好回源策略。
我是用的yeoman脚手架
與我同樣懶,連運行一下自動壓縮都不願意,也懶得寫插件(不過我倒是寫過代碼壓縮。。。)
不過支持自動壓縮與緩存的CDN也不是沒有啊,比如 Cloudflare。這無疑是最快最好的解決方案。
如果不能換CDN,CDN又不支持自定義的環境,本地壓縮就是唯一的解決方案,那麼可以考慮修改上傳用的腳本,實現真正自動壓縮。
總之啦,要麼時間花在寫程序上,要麼時間花在把自己變成程序一樣機械化執行命令上,要麼把時間花在尋求幫助上。
哪個最省事你已經知道了。
不過回答者大概也像你一樣懶?如果過幾天還沒有人提供完美解決方案,我就花幾分鐘幫你寫一個。真的很容易啦。
佔坑。
可以试试Google出的nginx
插件pagespeed!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics











What’s still popular is the ease of use, flexibility and a strong ecosystem. 1) Ease of use and simple syntax make it the first choice for beginners. 2) Closely integrated with web development, excellent interaction with HTTP requests and database. 3) The huge ecosystem provides a wealth of tools and libraries. 4) Active community and open source nature adapts them to new needs and technology trends.

HTML, CSS and JavaScript are the core technologies for building modern web pages: 1. HTML defines the web page structure, 2. CSS is responsible for the appearance of the web page, 3. JavaScript provides web page dynamics and interactivity, and they work together to create a website with a good user experience.

Importing WordPress source code requires the following steps: Create a sub-theme for theme modification. Import the source code and overwrite the files in the sub-topic. Activate the sub-theme to make it effective. Test the changes to make sure everything works.

The top ten safe and reliable exchanges in the 2025 cryptocurrency circle include: 1. Binance, 2. OKX, 3. Gate.io (Sesame Open), 4. Coinbase, 5. Kraken, 6. Huobi Global, 7. Gemini, 8. Crypto.com, 9. Bitfinex, 10. KuCoin. These exchanges are rated as safe and reliable based on compliance, technical strength and user feedback.

IIS and PHP are compatible and are implemented through FastCGI. 1.IIS forwards the .php file request to the FastCGI module through the configuration file. 2. The FastCGI module starts the PHP process to process requests to improve performance and stability. 3. In actual applications, you need to pay attention to configuration details, error debugging and performance optimization.

Multiple calls to session_start() will result in warning messages and possible data overwrites. 1) PHP will issue a warning, prompting that the session has been started. 2) It may cause unexpected overwriting of session data. 3) Use session_status() to check the session status to avoid repeated calls.

AI can help optimize the use of Composer. Specific methods include: 1. Dependency management optimization: AI analyzes dependencies, recommends the best version combination, and reduces conflicts. 2. Automated code generation: AI generates composer.json files that conform to best practices. 3. Improve code quality: AI detects potential problems, provides optimization suggestions, and improves code quality. These methods are implemented through machine learning and natural language processing technologies to help developers improve efficiency and code quality.

Laravel optimizes the web development process including: 1. Use the routing system to manage the URL structure; 2. Use the Blade template engine to simplify view development; 3. Handle time-consuming tasks through queues; 4. Use EloquentORM to simplify database operations; 5. Follow best practices to improve code quality and maintainability.
