Make WordPress Core

Opened 3 months ago

Closed 2 months ago

Last modified 5 weeks ago

#64428 closed enhancement (fixed)

Stop sending SCRIPT and STYLE type attribute for default values.

Reported by: dmsnell's profile dmsnell Owned by: jonsurrell's profile jonsurrell
Milestone: 7.0 Priority: normal
Severity: normal Version:
Component: Script Loader Keywords: has-patch needs-docs
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 3 months 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 3 months 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 (23)

#1 @westonruter
3 months ago

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

#2 @westonruter
3 months ago

  • Component changed from HTML API to Script Loader

#3 @jonsurrell
3 months 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
3 months 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.


3 months ago
#4

  • Keywords has-patch added; needs-patch removed

Trac ticket:

@hardikhuptechdev
3 months 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
3 months 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:


3 months 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:


3 months 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 months 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 months ago
#9

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

#11 @jonsurrell
2 months ago

  • Owner set to jonsurrell
  • Resolution set to fixed
  • Status changed from new to closed

In 61411:

Scripts: Remove default type attribute from tags.

SCRIPT, STYLE, and stylesheet LINK tags do not require a type attribute since the HTML5 standard was released in 2008. Removing the type attribute simplifies logic and normalizes the produced HTML content.

Developed in https://github.com/WordPress/wordpress-develop/pull/10658.

Follow-up to [46164].

Props hardikhuptechdev, jonsurrell, dmsnell, westonruter.
Fixes #64428. See #59883, #64442.

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


2 months ago
#12

Attributes like type="text/javascript" on script tags and type="text/css" on style tags are redundant in HTML5. Remove them.

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

Trac ticket: https://core.trac.wordpress.org/ticket/64428

#13 @jonsurrell
2 months ago

  • Resolution fixed deleted
  • Status changed from closed to reopened

I've opened PR 10664 to remove more redundant type attributes in wp-admin and themes.

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


2 months ago
#14

r61411 introduced a small regression where CDATA wrappers would be added to WP Admin for themes without HTML5 script support.

See https://github.com/WordPress/wordpress-develop/pull/10658#discussion_r2648473490 (thanks @sabernhardt).

Follow-up to r61411.

Trac ticket: https://core.trac.wordpress.org/ticket/64428

#15 @dmsnell
2 months ago

  • Keywords needs-docs added

Adding needs-docs to remember to add it to the HTML API Progress Report and Updates post for 7.0

#16 @jonsurrell
2 months ago

In 61414:

Scripts: Remove CDATA script wrappers in WP Admin.

Fix a regression from [61411] where CDATA wrappers were added to SCRIPT tags in WP Admin.

Developed in https://github.com/WordPress/wordpress-develop/pull/10666.

Follow-up to [61411].

Props sabernhardt.
See #64428, #59883.

@jonsurrell commented on PR #10666:


2 months ago
#17

Merged in r61414.

@westonruter commented on PR #10664:


2 months ago
#18

There are some additional instances of SCRIPT[type=text/javascript]:

src/wp-includes/js/tinymce/tiny_mce_popup.js:237:        document.write('<script type="text/javascript" src="' + url + '"></script>');
src/wp-includes/js/plupload/moxie.js:3697:		<script type="text/javascript">
src/wp-includes/script-loader.php:3557: *     $js = '<script type="text/javascript">console.log( "hi" );</script>';
src/wp-admin/includes/media.php:2073:	echo '<script type="text/javascript">post_id = ' . $post_id . ';</script>';
src/wp-admin/includes/media.php:2222:	<script type="text/javascript">
src/wp-admin/includes/media.php:2364:	<script type="text/javascript">
src/wp-admin/includes/media.php:2430:	<script type="text/javascript">
src/wp-admin/includes/media.php:2571:	<script type="text/javascript">
src/wp-admin/includes/media.php:2899:	<script type="text/javascript">

@jonsurrell commented on PR #10664:


2 months ago
#19

There are some additional instances of SCRIPT[type=text/javascript]

Thanks, I removed most of those. I did not modify the JavaScript files which appear to be plugins.

#20 @jonsurrell
2 months ago

  • Resolution set to fixed
  • Status changed from reopened to closed

In 61440:

Scripts: Remove default attributes from tags.

SCRIPT, STYLE, and stylesheet LINK tags do not require a type attribute since the HTML5 standard was released in 2008. Removing the type attribute simplifies logic and normalizes the produced HTML content.

Developed in https://github.com/WordPress/wordpress-develop/pull/10664.

Follow-up to [61411], [46164].

Props jonsurrell, sabernhardt, westonruter.
Fixes #64428. See #59883, #64442.

#21 @westonruter
5 weeks ago

#64575 was marked as a duplicate.

Note: See TracTickets for help on using tickets.