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

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

问题描述

我找不到有关Yii的AssetManager来管理JS和CSS文件的太多信息.我的问题是使用AssetManager有什么意义?我不确定它会为我的开发过程带来什么价值,实际上,这似乎使我的代码变得复杂...每次更改脚本或CSS代码时,我都必须进入并删除自己的Assets文件夹以确保我有最新版本.

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函数始终将脚本标签放置在标头标签内,而不是按照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...

谢谢!

推荐答案

我敢肯定有人会比我自己回答得更好,但基本上是为了让您的 source 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.

从一件事上讲这有点安全,但是对我来说,主要的好处是您可以使用资产发布系统压缩和缩小资产,或者以其他方式处理您的资产,这样一来,它更容易实现将您的JS和CSS托管在CDN上,因为它们与您的代码库是分开的.

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天全站免登陆