-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Script Loader: Add sourceURL comment (attempt 2). #9672
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
31451f8
012eb7f
1cfa076
cd1a726
81f4805
2b2af0c
a639316
4f72a4b
f74e4b1
0163cc6
d0ea5ff
aa432f7
e032974
b29be70
15a4b50
1bbecc8
180acff
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -222,6 +222,20 @@ public function print_extra_script( $handle, $display = true ) { | |
return; | ||
} | ||
|
||
/* | ||
* Do not print a sourceURL comment if concatenation is enabled. | ||
* | ||
* Extra scripts may be concatenated into a single script. | ||
* The line-based sourceURL comments may a concatenated script and | ||
* do not make sense when multiple are joined together. | ||
*/ | ||
if ( ! $this->do_concat ) { | ||
$output .= sprintf( | ||
"\n//# sourceURL=%s", | ||
rawurlencode( "{$handle}-js-extra" ) | ||
); | ||
} | ||
|
||
if ( ! $display ) { | ||
return $output; | ||
} | ||
|
@@ -524,6 +538,17 @@ public function get_inline_script_data( $handle, $position = 'after' ) { | |
return ''; | ||
} | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To contrast this with There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 1bbecc8 |
||
/* | ||
* Print sourceURL comment regardless of concatenation. | ||
* | ||
* Inline scripts prevent scripts from being concatenated, so | ||
* sourceURL comments are safe to print for inline scripts. | ||
*/ | ||
$data[] = sprintf( | ||
'//# sourceURL=%s', | ||
westonruter marked this conversation as resolved.
Show resolved
Hide resolved
|
||
rawurlencode( "{$handle}-js-{$position}" ) | ||
); | ||
|
||
return trim( implode( "\n", $data ), "\n" ); | ||
} | ||
|
||
|
@@ -696,12 +721,15 @@ public function print_translations( $handle, $display = true ) { | |
return false; | ||
} | ||
|
||
$source_url = rawurlencode( "{$handle}-js-translations" ); | ||
|
||
$output = <<<JS | ||
( function( domain, translations ) { | ||
var localeData = translations.locale_data[ domain ] || translations.locale_data.messages; | ||
localeData[""].domain = domain; | ||
wp.i18n.setLocaleData( localeData, domain ); | ||
} )( "{$domain}", {$json_translations} ); | ||
//# sourceURL={$source_url} | ||
JS; | ||
|
||
if ( $display ) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2212,6 +2212,7 @@ function _print_scripts() { | |
echo "\n<script{$type_attr}>\n"; | ||
echo "/* <![CDATA[ */\n"; // Not needed in HTML 5. | ||
echo $wp_scripts->print_code; | ||
echo sprintf( "\n//# sourceURL=%s\n", rawurlencode( 'js-inline-concat-' . $concat ) ); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There's example output in tests, but this outputs a sourceURL like this: //# sourceURL=js-inline-concat-one%2Ctwo
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I like this, even if it is short-lived. 👍🏻 |
||
echo "/* ]]> */\n"; | ||
echo "</script>\n"; | ||
} | ||
|
@@ -2394,8 +2395,9 @@ function _print_styles() { | |
$dir = $wp_styles->text_direction; | ||
$ver = $wp_styles->default_version; | ||
|
||
$concat = str_split( $concat, 128 ); | ||
$concatenated = ''; | ||
$concat_source_url = 'css-inline-concat-' . $concat; | ||
$concat = str_split( $concat, 128 ); | ||
$concatenated = ''; | ||
|
||
foreach ( $concat as $key => $chunk ) { | ||
$concatenated .= "&load%5Bchunk_{$key}%5D={$chunk}"; | ||
|
@@ -2407,6 +2409,7 @@ function _print_styles() { | |
if ( ! empty( $wp_styles->print_code ) ) { | ||
echo "<style{$type_attr}>\n"; | ||
echo $wp_styles->print_code; | ||
echo sprintf( "\n/*# sourceURL=%s */", rawurlencode( $concat_source_url ) ); | ||
echo "\n</style>\n"; | ||
} | ||
} | ||
|
Uh oh!
There was an error while loading. Please reload this page.