Jump to content

CCC JavaScript file - how to load it async?


hakeryk2

Recommended Posts

Hi developers,

Can anyone can tell me where I can find a code which is responsible for creating combined js file of all js files?

I mean everytime in footer we can find file like v_235_a8347981273902.js which is combined js file with all of the files. 

I want to know where I can find function responsible for creating this code because I want to ad async parameter to this script <script> 

Anyone?

 

This is even more funny because if I will put some js manually in code like in footer.tpl

<script async="async" defer type="text/javascript" src="{if isset($force_ssl) && $force_ssl}{$base_dir_ssl}themes/default-bootstrap{else}{$base_dir}themes/default-bootstrap{/if}/fastjs.js?ver=1.42"></script>

then in final code asyn="async" is deleted.

 

I found out that responsible for this is function in back office "Move JavaScript to the end" because when it's set to NO then everything works but then JavaScript is not at the bottom of document so it's bad to me.

 

I have  checked minify_html.class.php, HTMLPurifier.standalone and Media.php and it looks like the answer to my question is there but I can't find any piece of code that will match my request.

Edited by hakeryk2 (see edit history)
Link to comment
Share on other sites

  • 2 years later...

So I discovered all the JS files are referenced in templates/_partials/javascript.tpl in your theme.

I simply added the defer attribute for all external scripts.

Now, even with CCC turned on for JS, the defer attribute persists.

Didnt think it would be so easy!

This was all I wanted to keep gtmetrix.com happy :)

Link to comment
Share on other sites

  • 2 years later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...