How to cache external Javascript files?

What is the best way to add JavaScript or CSS files of modules in the Yii framework?

  • If you want to locate javascript or css files into a module of your yii application, then the file would be placed into your protected folder. But you can not access your javascript or css files outside your proteced folder.

  • Answer:

    Possible solution: Add to the module's  xxxModule.php file, into the init() function this code: $urlScript = Yii::app()->assetManager->publish(Yii::getPathOfAlias('MODULE_NAME').'/js/script.js', false, -1, true); Yii::app()->clientScript->registerScriptFile($urlScript, CClientScript::POS_HEAD);

Toni Jung at Quora Visit the source

Was this solution helpful to you?

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.