Still on Drupal 7? Security support for Drupal 7 ended on 5 January 2025. Please visit our Drupal 7 End of Life resources page to review all of your options.
JS path enhances any theme by allowing the front-end developer the opportunity to automatically include and cache javascript into pages and forms by js file naming conventions.
Example #1: If you desire to use jQuery (included in your theme) to add input tag events to a content type edit form with the <form id="post-node-form"> then you save your js file as "js/forms/post_node_form.js" within your current theme's folder.
Example #2: If you have multiple interactive articles posted under the relative URL "/articles/interactive" and you want to append a common JavaScript file to only the pages under that path, then you would save your js file as "js/paths/articles-interactive.js".
For example 2 it searches recursively from more to less specific and stops to inject the script once it finds a match (i.e. if your js file was named "js/paths/articles-interactive.js" then it would apply that first and never find "js/paths/articles.js"). This could change if other contributors have better suggestions. In the mean time, if you wanted to include articles.js INTO articles-interactive.js then you could use jQuery to load that script synchronously as a requirement of the articles-interactive.js file. An example of that would be: