2

In my Laravel site, I am serving my assets via CDN at https://cdn.example.com/asset.js. If I know the asset name, how can I generate a URL to the asset?

So far I have managed to generate https://example.com/asset.js by doing asset(Storage::url('asset.js'));, but I can't figure out how to add the subdomain, either by calling different methods or editing config.

Any ideas?

Cheers.

Votemike
  • 762
  • 1
  • 10
  • 28

2 Answers2

0

put your assets in public folder within or without folder and fetch those assets like css, js or any with

{{ asset('myassset.js') }}

or if in any folder then

{{ asset('myfolder/asset.js') }}

`

Umair Gul
  • 352
  • 1
  • 4
  • 15
0

Consider creating a custom function that can be called with asset_cdn('asset.js') might a better solution.

function asset_cdn( $asset, $secure = false ){
   $protocol = $secure ? 'https:' : 'http:';

   return $protocol . '//cdn.example.com/' . $asset;
}

How to make custom function in here.

vozaldi
  • 1,014
  • 9
  • 18