Jump to content

Change scripts loading order


Chaaampy

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}
  </script>
{/ 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}
  </script>
{/ 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 1.7.7.0 for info.

Thank you,

Link to comment
Share on other sites

  • 4 months later...

Hi,

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)

$this->registerJavascript(
	'module-modulename-simple-lib',
	'modules/'.$this->module->name.'/js/lib/simple-lib.js',
	[
	  'priority' => 200,
	  'attribute' => 'async',
	]
);

 

Link to comment
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...