Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

Hi I wanted to know the advantage of registering Asset Bundle following the process described in the docs like Process one in AppAsset.php

public $js = [
        'js/myjsfile.js'
    ];

then in the view file adding Namespace like

namespace appassets;

and then adding the use statement like

use appassetsAppAsset;
AppAsset::register($this);

Instead of doing all this if I use Process Two

$this->registerJs('js/myjsfile.js', $this::POS_READY);

it works fine. So why should I use Process One.

  1. Any advantage and reason for this will be greatly appreciated.
  2. If I follow the process one Do I need to add all the js files in AppAsset.php individually.

Thanks.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
308 views
Welcome To Ask or Share your Answers For Others

1 Answer

Asset Bundles have some advantages over normal registering. Apart from what @deacs said in his/her answer here are others:

  1. Assets Bundles can publish the file to assets if its not in web accessible directory
  2. Assets Bundle can deal with less files (in case of CSS) as well as compressing the assets.
  3. Makes Code Elegant especially in solving dependencies and hence reusability

All the features that makes bundles shine are found in docs


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...