Yii 的 AssetManager 有什么意义? [英] What's the point of Yii's AssetManager?

查看:13
本文介绍了Yii 的 AssetManager 有什么意义?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我找不到很多关于 Yii 的 AssetManager 用于管理 JS 和 CSS 文件的信息.我的问题是使用 AssetManager 有什么意义?我不确定它为我的开发过程增加了什么价值,事实上,它似乎使我的代码复杂化......每次我更改脚本或 css 代码时,我都必须进入并删除我的资产文件夹以确保我有最新版本.

I can't find much information about Yii's AssetManager for the management of JS and CSS files. My question here is what is the point of using the AssetManager? I'm not sure what value it adds to my development process, in fact, it seems like it complicates my code... every time I change my scripts or css code, I have to go in and delete my assets folder to make sure I have the latest versions.

似乎将所有 Javascript 文件放在/webroot/js/下并使用标签加载文件而不是通过 AssetManager 的麻烦要简单得多.另外,Yii 的 registerCoreScript 函数总是将脚本标签放在 header 标签内,而不是像 YSlow 推荐的那样将它们放在代码底部,靠近结束体标签.

Seems it is much simpler to just put all Javascript files under /webroot/js/ and just use the tags to load the files instead of going through the trouble of AssetManager. Plus, Yii's registerCoreScript function always places script tags inside the header tag, instead of placing them at the bottom of the code, near the closing body tag, as recommended by YSlow.

我觉得我对 Yii 的 AssetManager 的理解肯定有差距.任何人都知道为什么使用 AssetManager 比在 PHP 代码中硬编码脚本标签更好?我有点糊涂了...

I think there must be a gap in my understanding of Yii's AssetManager. Anybody have any ideas why using the AssetManager is better than hard-coding the script tags inside the PHP code? I'm a bit confused...

谢谢!

推荐答案

我相信有人能比我自己回答得更好,但基本上是为了让您的源代码 JS 和 CSS 文件可以保留在您的受保护文件夹.

I'm sure someone can answer this better than myself, but basically it's so that your source JS and CSS files can remain in your Protected folder.

一方面,这更安全一点,但对我来说的主要好处是您可以使用资产发布系统压缩和缩小以及以其他方式处理您的资产,并且它更容易在 CDN 上托管您的 JS 和 CSS,因为它与您的代码库是分开的.

This is a little more secure for one thing, but the main benefit to me is that you can compress and minify and otherwise process your assets with the asset publishing system, and it makes it easier to host your JS and CSS on a CDN since it's separate from your codebase.

此外,这是来自qiang的官方回复(写 Yii 的人)关于这个.

Also, here's an official response from qiang (the guy who wrote Yii) about this.

这篇关于Yii 的 AssetManager 有什么意义?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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