The JavaScript Example module shows how to load a JavaScript file before another one, by setting the weight property for each file.

That is a bad example, as the comments say, but it is also not necessary: Drupal core includes the loadjs library, which exactly for running JavaScript code once a file has been loaded from the browser. It is only used by Drupal.ajax, but the code used from Drupal core can be used as example to write our code.

As to show how to use a property for assets files part of a library, it would be sufficient to use attributes and id.

Issue fork examples-3461179

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

apaderno created an issue. See original summary.

avpaderno’s picture

Component: JavaScript Example » Code

avpaderno changed the visibility of the branch 3461179-do-not-use-weight-forjs-files to hidden.

avpaderno’s picture

Status: Active » Needs review

  • avpaderno committed e74b5f98 on 4.0.x
    Issue #3461179: Change the .libraries.yml file not to use weight for...
avpaderno’s picture

Status: Needs review » Fixed

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.