Jump to content

Change scripts loading order


Recommended Posts

Hello everyone,

I am facing a problem, which I have to resolve fairly quickly (as usual).

To achieve that, I have to change the scripts loading order in my javascript.tpl file.

Specifically, in this block of code:


{foreach $ javascript.external as $ js}
  <script type = "text / javascript" src = "{$ js.uri}" {$ js.attribute}> </script>
{/ foreach}

{foreach $ javascript.inline as $ js}
  <script type = "text / javascript">
    {$ js.content nofilter}
{/ foreach}

{if isset ($ vars) && $ vars | @count}
  <script type = "text / javascript">
    {foreach from = $ vars key = var_name item = var_value}
    var {$ var_name} = {$ var_value | json_encode nofilter};
    {/ foreach}
{/ if}


To be even more precise, I would have to be able to load my custom.js file a little before (it is currently loaded last), because the file loaded before my custom scripts causes it to crash (idk why) on a very specific page.

I'm on for info.

Thank you,

Share this post

Link to post
Share on other sites

  • 4 months later...


If the js are placed from modules, change the order of the hook positions so that the order in which they are loaded will change.

Or, when you register your js, you can prioritize it (0 is the highest priority)

	  'priority' => 200,
	  'attribute' => 'async',


Share this post

Link to post
Share on other sites

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...

Important Information

Cookies ensure the smooth running of our services. Using these, you accept the use of cookies. Learn More