#64428 closed enhancement (fixed)
Stop sending SCRIPT and STYLE type attribute for default values.
| Reported by: |
|
Owned by: |
|
|---|---|---|---|
| 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)
Change History (23)
@
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:
@
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
@
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
assertEqualHTMLis updated to count the absence oftypeas the same as iftype="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.
@jonsurrell commented on PR #10658:
2 months ago
#10
This has a lot of overlap with https://github.com/WordPress/wordpress-develop/pull/10660.
#11
@
2 months ago
- Owner set to jonsurrell
- Resolution set to fixed
- Status changed from new to closed
In 61411:
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
@
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
@
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
@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.
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.