Make WordPress Core

Opened 18 months ago

Closed 18 months ago

Last modified 18 months ago

#58974 closed enhancement (fixed)

Modernize wp-embed script to remove IE≤11 code and support for WP<4.4

Reported by: westonruter's profile westonruter Owned by: westonruter's profile westonruter
Milestone: 6.4 Priority: normal
Severity: normal Version: 4.4
Component: Embeds Keywords: has-patch has-unit-tests
Focuses: javascript Cc:

Description (last modified by westonruter)

In the course of making the wp-embed script use the defer loading strategy (#58931), I found that there was some old code for IE10/IE11 which we can remove now since those browsers are longer supported. Also, since they're not supported anymore we can freely make use of URL instead of hacking URL parsing with document.createElement('a'). Lastly, the code includes a load event on the window as an apparently fallback for browsers which don't support DOMContentLoaded, so that event listener can be removed as well.

Aside: I noticed that the deprecated substr() string method is being used which should be replaced with substring() or slice().

Nevertheless, as I started modernizing the wp-embed codebase I started running into another problem: the stipulation that wp-embed.js (and the generated wp-embed.min.js) not have any ampersands. This came up in #34698 for which r35708 notes:

Embeds: Remove & characters from the inline embed JS.

Older versions of WordPress will convert those & characters to &#038;, which makes for some non-functional JS. If folks are running an older release, let's not make their lives more difficult than it already is.

This was introduced in WordPress 4.4, so the older versions in mind are WordPress 4.3 and below. At this time, according to WordPress stats, all versions below 4.4 add up to 1.43% of the market share:

Version Percentage
4.3 0.22%
4.2 0.21%
4.1 0.19%
4.0 0.13%
3.9 0.14%
3.8 0.07%
3.7 0.02%
3.6 0.08%
3.5 0.11%
3.4 0.07%
3.3 0.05%
3.2 0.03%
3.1 0.04%
3.0 0.07%
SUM: 1.43%

So it seems the relevant changes for that ticket (r35708, r35762, and later r50441) can be safely reverted now and the use of ampersands can be allowed again in wp-embed.

Change History (8)

#1 @westonruter
18 months ago

  • Owner set to westonruter
  • Status changed from new to accepted

#2 @westonruter
18 months ago

  • Description modified (diff)

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


18 months ago
#3

  • Keywords has-patch has-unit-tests added
  • Remove obsolete load event handler in wp-embed since IE10+ support DOMContentLoaded.
  • Replace obsolete use of document.createElement('a') in favor of the newer URL class (supported in all browsers but obsolete IE11).
  • Remove obsolete IE10/IE11 code.
  • Combine condtionals.
  • Use `substring()` instead of deprecated `substr()` method.
  • Eliminate the stipulation that wp-embed.js not include ampersands, considering this was put in place for WP<4.3 which now accounts for only 1.43% of sites. This includes the elimination of the verify:wp-embed grunt task.

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

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


18 months ago
#4

  • Remove obsolete load event handler in wp-embed since IE10+ support DOMContentLoaded.
  • Replace obsolete use of document.createElement('a') in favor of the newer URL class (supported in all browsers but obsolete IE11).
  • Remove obsolete IE10/IE11 code.
  • Combine conditionals.
  • Use `substring()` instead of deprecated `substr()` method.
  • Eliminate the stipulation that wp-embed.js not include ampersands, considering this was put in place for WP<4.3 which now accounts for only 1.43% of sites. This includes the elimination of the verify:wp-embed grunt task.

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

@westonruter commented on PR #4964:


18 months ago
#5

I erroneously pushed the branch to origin and not to my fork. Closing this PR in favor of #4967

@westonruter commented on PR #4964:


18 months ago
#6

I erroneously pushed the branch to origin and not to my fork.

This won't happen again, thanks to:

git remote set-url --push origin https://github.com/westonruter/wordpress-develop.git

#7 @westonruter
18 months ago

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

In 56383:

Embeds: Modernize wp-embed script with removal of obsolete IE10/IE11 code and support for WP<4.4.

  • Remove obsolete load event handler in wp-embed since IE10+ support DOMContentLoaded.
  • Replace obsolete use of document.createElement('a') in favor of the newer URL class (supported in all browsers but obsolete IE11).
  • Remove obsolete IE10/IE11 code.
  • Combine conditionals.
  • Use substring() instead of deprecated substr() method.
  • Eliminate the stipulation that wp-embed.js not include ampersands, considering this was put in place for WP<4.3 which now accounts for only 1.43% of sites. This includes the elimination of the verify:wp-embed grunt task.

Props westonruter, swissspidy.
Fixes #58974.

Note: See TracTickets for help on using tickets.