A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/yiisoft/yii2/issues/17673 below:

Javascript registered in renderDynamic doesn't appear anywhere when PageCache is used · Issue #17673 · yiisoft/yii2 · GitHub

JS or CSS registered with registerJS, registerJSFile etc will not work in renderDynamic. This problem causes, that it is not possible to use any widgets in renderDynamic on a cached page which has JavaScript or CSS assets. This issue is basically #16051 re-opened with simple step-step reproducing.

What steps will reproduce the problem?
  1. Create a YII2 system with the Basic Template and go there:
composer create-project --prefer-dist yiisoft/yii2-app-basic basic
cd basic
  1. Add the following line as line 2 in views/site/index.php:
$this->renderDynamic('$this->registerJs("alert(\'JS started\')");');
  1. Start the simple WEB server
php yii serve --port=8888
  1. Go in browser to http://localhost:8888 Te alert box will appear, and you can find the following lines also in the page source:
<script src="<script>jQuery(function ($) {
alert('JS started')
});</script>
  1. Now add PageCache to the Index action. Add the following code in the function behaviors in controllers/SiteController.php:
'indexCache' => [ 
    'class' => 'yii\filters\PageCache',
    'only' => ['index'],
    'duration' => 86400,    // 1 day
    'enabled' => true,
],
  1. Check again the Home page. The JS code and the alert IS NOT INCLUDED anymore.
What is the expected result?

The registered JavaScript should appear in the HTML page.

What do you get instead?

All Javascript registered in renderDynamic is missing.

Additional info Q A Yii version 2.0.29 PHP version PHP 7.2.24-1+ubuntu16.04.1+deb.sury.org+1 Operating system Ubuntu 16.04

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4