Skip to content

Commit 00aa088

Browse files
Copilotsamdark
andauthored
docs: Add $cdn property to CDN Assets example (#393)
Co-authored-by: samdark <47294+samdark@users.noreply.github.com> Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
1 parent 71b2970 commit 00aa088

1 file changed

Lines changed: 14 additions & 11 deletions

File tree

src/guide/views/asset.md

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -306,16 +306,10 @@ final class JqueryAsset extends AssetBundle
306306
{
307307
public string $basePath = '@assets';
308308
public string $baseUrl = '@assetsUrl';
309-
309+
310310
public array $js = [
311311
'js/jquery-3.6.0.min.js',
312312
];
313-
314-
// Or use CDN
315-
public array $jsOptions = [
316-
'integrity' => 'sha256-...',
317-
'crossorigin' => 'anonymous',
318-
];
319313
}
320314
```
321315

@@ -351,7 +345,9 @@ final class BootstrapAsset extends AssetBundle
351345

352346
### CDN Assets
353347

354-
For CDN-hosted assets, you can specify full URLs:
348+
For CDN-hosted assets, set `$cdn` to `true` and use full URLs for your asset files. Setting `$cdn = true`
349+
tells the asset manager that the assets are served from an external CDN, so it skips local file publishing
350+
and path resolution. The `$basePath` and `$baseUrl` properties aren't needed in this case.
355351

356352
```php
357353
<?php
@@ -362,16 +358,23 @@ namespace App\Asset;
362358

363359
use Yiisoft\Assets\AssetBundle;
364360

365-
final class CdnAsset extends AssetBundle
361+
final class BootstrapCdnAsset extends AssetBundle
366362
{
363+
public bool $cdn = true;
364+
367365
public array $css = [
368366
'https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css',
369367
];
370-
368+
369+
public array $cssOptions = [
370+
'integrity' => 'sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3',
371+
'crossorigin' => 'anonymous',
372+
];
373+
371374
public array $js = [
372375
'https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js',
373376
];
374-
377+
375378
public array $jsOptions = [
376379
'integrity' => 'sha384-ka7Sk0Gln4gmtz2MlQnikT1wXgYsOg+OMhuP+IlRH9sENBO0LRn5q+8nbTov4+1p',
377380
'crossorigin' => 'anonymous',

0 commit comments

Comments
 (0)