2
I’m using the PHP Cakephp Framework 3.0.3 and would like to know how to insert the keywords Defer and async script tags and omit values:
How script insertion is done with the framework:
<?= $this->Html->script('jquery-1.11.1.min.js') ?>
How is rendered:
<script src="/js/jquery-1.11.1.min.js"></script>
As I’d like it to be:
<script async src="/js/jquery-1.11.1.min.js"></script>
<script defer src="/js/jquery-1.11.1.min.js"></script>
In the documentation I saw nothing I could make this insertion.
An alternative way I’m using is to do it this way:
<?= $this->Html->script('jquery-1.11.1.min.js',['defer' => true]) ?>
and this rendering:
<script src="/js/jquery-1.11.1.min.js" defer="defer"></script>
Do you want this by default at all? Why do you consider gambiarra
["defer" => true]
?– Wallace Maxters
@Wallacemaxters why it generates a different result than expected, but I will change the gambiarra
– Ricardo
I used to use that term a lot :)
– Wallace Maxters
In my opinion, you should create a helper and extender Htmlhelper
– Wallace Maxters
This extending the Htmlhelper class is worth a great answer (if added with an example). @Wallacemaxters
– Guilherme Nascimento
@Ricardo on p
['defer'=>true]
or[defer]
begetdefer="defer"
seems to be cakephp’s own. Maybe just extending the classCake\View\Helper\HtmlHelper
same. An example that proves to be really the result Htmlhelper::media– Guilherme Nascimento