缩小并合并文件 - 您的开发和发布设置是什么?
我目前正在使用 PHP minify 来组合和压缩静态文件(CSS 和 JS)。使用 PHP minify,开发和部署非常容易。因为:
假设有两个文件:a.js
和 b.js
,我们在 ab.js
中组合并缩小它们。现在,我只包含一个脚本标签就足够了:
<script type="text/javascript" src="http://static.example.com/min/g=ab&v=7"></script>
有了这种灵活性,我可以在 a.js 和 b.js 中进行开发,同时测试最终的缩小版本,而无需更改上面的 include 标签。我什至不需要在发布时进行更改。
但现在我想将我的静态文件移动到 PHP 不会在那里的 CDN 服务器,所以我想我必须在上传之前使用 YUI 压缩器来缩小和组合。现在,如果我将 a.js 和 b.js 与 YUI 压缩器结合起来,我必须更改我用来开发的 include 标签。
因此,在开发时我必须使用:
<script type="text/javascript" src="http://static.example.com/a.js"></script>
<script type="text/javascript" src="http://static.example.com/b.js"></script>
并且在上传时我必须使用:
<script type="text/javascript" src="http://static.example.com/ab.min.js"></script>
然后它就成为一个问题,因为这两行必须合并为一行。你的设置是什么来管理这个?
I am currently using PHP minify to combine and compress the static files (CSS and JS). With PHP minify it is very easy to develop and deploy. Because:
Say there are two files: a.js
and b.js
and we combine and minify them in ab.js
. Now its enough for me to include only one script tag:
<script type="text/javascript" src="http://static.example.com/min/g=ab&v=7"></script>
With this flexibility I can develop in a.js and b.js and at the same time test the final minified version without changing the include tag above. I don't even need to change while releasing.
But now I want to move my static files to CDN server where PHP won't be there, so I guess I have to use YUI compressor to minify and combine before uploading. Now If I am combining a.js and b.js with YUI compressor, I have to change the include tag which I used to develop.
So when developing I've to use:
<script type="text/javascript" src="http://static.example.com/a.js"></script>
<script type="text/javascript" src="http://static.example.com/b.js"></script>
And when uploading I've to use:
<script type="text/javascript" src="http://static.example.com/ab.min.js"></script>
Then it becomes a problem because, the two lines has to be combined into one. Whats your setup to manage this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
将基本 URL 指定为 ab.min.js(即 http://static.example.com/)在配置文件中。在生产配置中,使用 CDN 位置。在您的开发配置中,使用自动缩小的位置。
Specify the base URL to ab.min.js (i.e. http://static.example.com/) in a config file. In the production config, use the CDN location. In your development config, use the automatically minified location.
看起来您很乐意使用不同的基本 URL 进行开发和生产,但是将两行合并为一行是您的问题。
如果是这种情况,也许您想将此步骤分成两部分。
如果您想将 a.js 和 b.js 分开,那么上述内容对您不起作用,您可能需要某种预处理器来根据需要修改源代码中的脚本标签。
Looks like you're comfortable with using different base URLs for development and production, but that combining two lines into one is your problem.
If this is the case, perhaps you want to split this step in two.
If you want to keep a.js and b.js separated, then the above will not work for you and you probably need some kind of preprocessor that will modify the script tags in your source code as required.