drupal_add_js() is missing the 'browsers' option

Created on 26 July 2010, almost 15 years ago
Updated 4 May 2025, 9 days ago

Problem

  • CSS can be conditionally loaded for limited 'browsers' (e.g., IE) only, but JS cannot.
  • #1077878: Add HTML5shiv to core cannot be done without conditional comment support for JS.
  • Modules like No IE6 cannot load JavaScript files for specific browsers.

Proposed solution

  • Make it consistent with drupal_add_css
  • Hacking a #browsers condition into the current code of drupal_get_js() doesn't really make sense.
  • Instead, further align drupal_get_js() with drupal_get_css(), as originally proposed in #330082-20: Refactor drupal_get_js() to use render layer similar to drupal_get_css() already.
  • Introduce #type 'scripts' -- equivalent to existing #type 'styles'.
  • As already the case for #type 'styles' / drupal_get_css(), properly separate the current processing of JS into a #group_callback and #aggregate_callback.

    Side-benefit: Default behavior can be changed and improved in contrib.

  • Only do the necessary to align #type 'scripts' with 'styles', and to introduce support for 'browsers'.

    A major long-term benefit of doing so is that we're finally able to abstract and merge further parts of the #group_callback and #aggregate_callback logic into common helper functions -- paving the way to get to the long-standing idea of having a single generalized system for "support files"/"page requisites" in Drupal core.

Current State

The last patch submitted #136 has been RTBC.
This patch does everything proposed. It also passed all the JS test, and a couple of new test were added.

Seems good to go.

Feature request
Status

Fixed

Version

8.0 ⚰️

Component

javascript

Created by

🇪🇸Spain altrugon

Live updates comments and jobs are added and updated live.
  • html5

    Implements and supports the use of HTML5.

  • Needs backport to D7

    After being applied to the 8.x branch, it should be considered for backport to the 7.x branch. Note: This tag should generally remain even after the backport has been written, approved, and committed.

Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024