Make WordPress Core


Ignore:
Timestamp:
05/09/2023 12:15:44 PM (3 years ago)
Author:
audrasjb
Message:

Script Loader: Optimize performance of _wp_normalize_relative_css_links() by more than 2x.

  • Replace preg_match_all() and its secondary str_replace() call with preg_replace_callback().
  • Fix case where paths beginning with http and https (but not http: and https:) were erroneously not counted as relative.
  • Improve code style and readability by consolidating conditions and returning once.
  • Use str_starts_with() consistently instead of strpos().

Follow-up to [52036], [52695], and [52754].

Props westonruter, adamsilverstein, azaozz.
Merges [55658] and [55669] to the 6.2 branch.
Fixes #58069.
See #54243.

Location:
branches/6.2
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/6.2

  • branches/6.2/tests/phpunit/tests/dependencies/styles.php

    r55368 r55736  
    197197         * @ticket 54243
    198198         * @ticket 54922
     199         * @ticket 58069
    199200         *
    200201         * @covers ::_wp_normalize_relative_css_links
    … …  
    240241                                'css'      => 'img {mask-image: url(\'data:image/svg+xml;utf8,<svg></svg>\');}',
    241242                                'expected' => 'img {mask-image: url(\'data:image/svg+xml;utf8,<svg></svg>\');}',
     243                        ),
     244                        'URLs with path beginning with http'           => array(
     245                                'css'      => 'p {background:url( "http-is-awesome.png" );}',
     246                                'expected' => 'p {background:url( "/wp-content/themes/test/http-is-awesome.png" );}',
     247                        ),
     248                        'URLs with path beginning with https'          => array(
     249                                'css'      => 'p {background:url( "https-is-more-awesome.png" );}',
     250                                'expected' => 'p {background:url( "/wp-content/themes/test/https-is-more-awesome.png" );}',
    242251                        ),
    243252                );
Note: See TracChangeset for help on using the changeset viewer.