M
M
Monitorkin2017-05-31 08:42:32
Yii
Monitorkin, 2017-05-31 08:42:32

How to enable async defer options when loading a script?

Hello, from the documentation for connecting google map, you need to write the following line:

<script src="https://maps.googleapis.com/maps/api/js?key=YOUR_API_KEY&callback=initMap"
    async defer>
</script>

In my application, the script is loaded like this:
$this->registerJsFile('https://maps.googleapis.com/maps/api/js?key='.Yii::$app->params['google']['map_api_key'].'&callback=initMap',  ['position' => $this::POS_END]);

How can I specify the parameters of the async defer script in this line ?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
Maxim Timofeev, 2017-05-31
@Monitorkin

Try like this:

$this->registerJsFile(
'link',  
['position' => $this::POS_END, 'async'=>true, 'defer'=>true]);

or so
$this->registerJsFile(
'link',  
['position' => $this::POS_END, 'async'=>'async', 'defer'=>'defer']);

M
Maxim Fedorov, 2017-05-31
@qonand

$this->registerJsFile('https://maps.googleapis.com/maps/api/js?key='.Yii::$app->params['google']['map_api_key'].'&callback=initMap',  [
    'position' => $this::POS_END,
    'async' => 'async',
    'defer' => 'defer'
]);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question