When I am learning Yii recently and loading CSS, JS, etc., I can load resources by directly writing link tags or using AppAsset. So the question is, which method is better and why?
巴扎黑2017-05-16 13:03:16
Yii’s AppAsset can realize automatic loading of static file dependencies and compression and merging of multiple files.
For example, if you have a plug-in that relies on jQuery, after using AppAsset, the system will automatically load the plug-in after jQuery, and can merge multiple js files into one and compress them, reducing the number of times the page loads files.
迷茫2017-05-16 13:03:16
Personally, I think it’s for the purpose of protecting the directory structure
黄舟2017-05-16 13:03:16
There are many benefits. It can cache files. The cache directory is the cache directory of your project. If you don’t want people to know the addresses of your files, it will be very safe to use AppAsset because others cannot go there based on the address of your files. Do some tricks on your website.
Also, the styles in the extension will also be cached. If you directly use an address like vendor/kuozhan/web/css/style.css, then you will expose something, which is very dangerous. On the contrary, if you use appasset, it will only display /assets/ead333c7/yii.js, which is very spiritual. If your opponent can't guess your thoughts, you win.