'How can i add a hash in my $jsOptions on Yii2

I want hashing my assets on yii2, but i can´t find the way to do it, can you help me please?

Exactly in this parte of my AppAsset.php

public $jsOptions = [
    'defer' => 'defer',
  ];


Solution 1:[1]

If I understand what you mean correctly,

// code ...
public $js = [
    ['js/first.js','integrity' => '{hash}'],
    ['js/second.js','integrity' => '{hash2}'],
];
public $jsOptions = [
    'crossorigin' => 'anonymous',
     // 'async' => 'async',  {or defer}
];
// code ...

If you use Hash in jsOptions, it is used for all JS files:

public $js = [
    'js/first.js',
    'js/second.js',
];
public $jsOptions = [
    'integrity' => '{hash}';
    'crossorigin' => 'anonymous',
];

For sha256, sha384, sha512 algorithms

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 user206