Make WordPress Core

Opened 8 days ago

Last modified 2 days ago

#64428 new enhancement

Stop sending SCRIPT and STYLE type attribute for default values.

Reported by: dmsnell's profile dmsnell Owned by:
Milestone: 7.0 Priority: normal
Severity: normal Version:
Component: Script Loader Keywords: has-patch
Focuses: Cc:

Description

The script-loader and WP_Styles both make checks against current_theme_supports( 'html5', 'style' ) and current_theme_supports( 'html5', 'script' ), and multiple places in the rest of the codebase unconditionally produce type="text/css" and type="text/javascript" HTML attributes on the associated tags.

This is a legacy convention predating HTML5 in 2008 and can be removed. These are the default values when the attributes are absent, and this does not depend on or change with declared theme support.

Removing the type attribute simplifies logic and normalizes the produced HTML content.

This is part of #59883

See also PR#10641

Attachments (2)

64428.diff (5.4 KB) - added by hardikhuptechdev 7 days ago.
Removes redundant type attributes (text/javascript and text/css) from SCRIPT and STYLE tags. Verified via PHPCS and PHPUnit; no regressions found.
64428.2.diff (6.0 KB) - added by hardikhuptechdev 7 days ago.
Rebuilt patch from trunk. Removes default type attributes from SCRIPT and STYLE elements. Verified with npm run build and PHPUnit; passes tests.

Download all attachments as: .zip

Change History (12)

#1 @westonruter
8 days ago

  • Keywords needs-patch added
  • Milestone changed from Awaiting Review to 7.0

#2 @westonruter
8 days ago

  • Component changed from HTML API to Script Loader

#3 @jonsurrell
8 days ago

The CDATA wrappers added to SCRIPT tags are a similar feature that should be good to remove as well, that can be a separate ticket and related to follow-up work on #64419.

@hardikhuptechdev
7 days ago

Removes redundant type attributes (text/javascript and text/css) from SCRIPT and STYLE tags. Verified via PHPCS and PHPUnit; no regressions found.

This ticket was mentioned in PR #10645 on WordPress/wordpress-develop by @hardikhuptechdev.


7 days ago
#4

  • Keywords has-patch added; needs-patch removed

Trac ticket:

@hardikhuptechdev
7 days ago

Rebuilt patch from trunk. Removes default type attributes from SCRIPT and STYLE elements. Verified with npm run build and PHPUnit; passes tests.

#5 @jonsurrell
7 days ago

Thanks @hardikhuptechdev. Just for clarity, creating a PR like this is sufficient, there's no need to upload patches here.

@westonruter commented on PR #10645:


7 days ago
#6

A whole bunch of unit tests will need to be updated to account for the removal of the type attribute. That is, unless assertEqualHTML is updated to count the absence of type as the same as if type="text/javascript" is present?

@jonsurrell commented on PR #10645:


7 days ago
#7

unless assertEqualHTML is updated to count the absence of type as the same as if type="text/javascript" is present?

I think it's important that these tests show differences in this case. I'd like assertEqualHTML to remain a faithful representation of the HTML.

This ticket was mentioned in PR #10658 on WordPress/wordpress-develop by @jonsurrell.


2 days ago
#8

  • Trac #64428: Remove default type attributes from SCRIPT and STYLE elements
  • Trac #64428: Restore CDATA condition and keep explicitly set script types.
  • Remove text/css type attribute from theme style tags
  • Remove text/css type attribute from theme link tags
  • Remove text/css type from style tags
  • Remove type-attr from class-wp-styles
  • Remove text/css type from class-wp-font-face
  • Remove text/css type from Core LINK tags

Trac ticket:

@jonsurrell commented on PR #10645:


2 days ago
#9

I've done some more work on this ticket in https://github.com/WordPress/wordpress-develop/pull/10658.

Note: See TracTickets for help on using tickets.