Jump to content

  • You cannot start a new topic
  • You cannot reply to this topic

Cdn For {Script Src=""} Rate Topic   - - - - -

 
  • patroklos
  • Member
  • Members
  • Join Date: 13-Jun 19
  • 41 posts

Posted 12 May 2021 - 12:47 PM #1

Hi,

 

When CDN is enabled,

and you load a script through

the smarty {script src=""} syntax,

it does not use the CDN url.

 

The CDN is used only for the scripts.js file,

which you can extend using hooks/index/scripts.post.tpl .

 

But, If you want to load a js file in another tpl,

(for example a big js that is only needed in some pages),

the CDN url is not used.

 

Is there a fix for that?

 

Thanks.



 
  • tbirnseth
  • CS Cart Expert
  • Authorized Reseller
  • Join Date: 08-Nov 08
  • 12071 posts

Posted 12 May 2021 - 06:52 PM #2

You should be able to use the {script} tag in that other addon.


EZ Merchant Solutions: Custom (USA based) B2B Development, Consulting, Development and Special Projects (get a quote here).
Commercial addons, payment methods and modifications to meet your business and operations needs.


 
  • patroklos
  • Member
  • Members
  • Join Date: 13-Jun 19
  • 41 posts

Posted 13 May 2021 - 06:36 AM #3

Hi,

 

I think I didn't make it clear.

 

When I include scripts using the {script} syntax, the cdn url is not used.

 

That's what I m looking a solution for.

 

Thanks



 
  • harmsmitsdev
  • Senior Member
  • Members
  • Join Date: 22-Feb 20
  • 183 posts

Posted 13 May 2021 - 08:56 AM #4

Hi,

 

I think I didn't make it clear.

 

When I include scripts using the {script} syntax, the cdn url is not used.

 

That's what I m looking a solution for.

 

Thanks

Make sure to do

{scripts}
  {script src="..."}
{/scripts}

 


harmsmitsdev@gmail.com


 
  • patroklos
  • Member
  • Members
  • Join Date: 13-Jun 19
  • 41 posts

Posted 07 June 2021 - 12:13 PM #5

Hi,

 

Thanks for your response!

 

Unfortunately it throws errors like... 

 

"Tygh is not defined" and

"$ is not defined"

 

Very strange

Seems they forgot about that



 
  • patroklos
  • Member
  • Members
  • Join Date: 13-Jun 19
  • 41 posts

Posted 07 June 2021 - 01:31 PM #6

Managed to do it this way:

 

/** 
     * Create a script url that uses CDN.
     * 
     * @param string $src
     * @return string
     */
    function fn_my_changes_script_url($src){
        $url = \Tygh\Storage::instance('assets')->getUrl($src);
        //remove assets part
        $url = str_replace('/var/cache/misc/assets', '', $url);
        return $url;
    }
 
Called using:
 
<script src="{fn_my_changes_script_url('js/safssfa/asdf/asfd/asfd/123.js?v=2.3.4')}"></script>