Make WordPress Core


Ignore:
Timestamp:
09/08/2025 11:25:40 AM (2 months ago)
Author:
jonsurrell
Message:

Script Loader: Add sourceURL to inline scripts and styles.

Improve the source locations referenced by developer tooling in supporting browsers. Inline source locations are named like inline:handle-js-after and appear in the developer tools "sources" panel.

This is the second attempt to add sourceURL comments. The first attempt in [60685] was reverted due to an issue with script concatenation that has been addressed.

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

Follow-up to [60685], [60690].

Props jonsurrell, westonruter, wildworks, peterwilsoncc, johnbillion, tobiasbg.
Fixes #63887.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/script-loader.php

    r60704 r60719  
    22132213            echo "/* <![CDATA[ */\n"; // Not needed in HTML 5.
    22142214            echo $wp_scripts->print_code;
     2215            echo sprintf( "\n//# sourceURL=%s\n", rawurlencode( 'js-inline-concat-' . $concat ) );
    22152216            echo "/* ]]> */\n";
    22162217            echo "</script>\n";
     
    23952396        $ver = $wp_styles->default_version;
    23962397
    2397         $concat       = str_split( $concat, 128 );
    2398         $concatenated = '';
     2398        $concat_source_url = 'css-inline-concat-' . $concat;
     2399        $concat            = str_split( $concat, 128 );
     2400        $concatenated      = '';
    23992401
    24002402        foreach ( $concat as $key => $chunk ) {
     
    24082410            echo "<style{$type_attr}>\n";
    24092411            echo $wp_styles->print_code;
     2412            echo sprintf( "\n/*# sourceURL=%s */", rawurlencode( $concat_source_url ) );
    24102413            echo "\n</style>\n";
    24112414        }
Note: See TracChangeset for help on using the changeset viewer.