[wp-trac] [WordPress Trac] #63887: Add sourceURL to inline scripts and styles
WordPress Trac
noreply at wordpress.org
Mon Sep 1 06:40:51 UTC 2025
#63887: Add sourceURL to inline scripts and styles
--------------------------------------+------------------------------
Reporter: jonsurrell | Owner: jonsurrell
Type: enhancement | Status: reopened
Priority: normal | Milestone: 6.9
Component: Script Loader | Version:
Severity: normal | Resolution:
Keywords: has-patch has-unit-tests | Focuses: javascript, css
--------------------------------------+------------------------------
Comment (by westonruter):
Replying to [comment:24 johnbillion]:
> Weird that none of the e2e tests caught this. The suite runs one with
`SCRIPT_DEBUG` and once without. eg. https://github.com/WordPress
/wordpress-develop/actions/runs/17324288405/job/49184432082
Since the issue occurred in the Customizer per @wildworks, I think the
issue is that there [https://github.com/WordPress/wordpress-
develop/tree/trunk/tests/e2e/specs aren't any E2E tests] for the
Customizer (yet). This is noted in #52895 (from 4 years ago) as something
needing to be done.
Replying to [https://github.com/WordPress/wordpress-
develop/pull/9672#discussion_r2310878554 jonsurrell]:
> I suspect this would fix the issue, but I need to confirm this works in
browsers with the other comment format. I believe the spec only mentions
the `//` form.
>
> If it works, this is likely safer in general. However, it doesn't make
sense to add several of these comments in a concatenated script.
>
> I think we should disable this behavior if scripts are being
concatenated, or possibly only enable with SCRIPT_DEBUG = true.
I enabled script concatenation by updating my `wp-config.php` in the
wordpress-develop repo to have:
{{{#!php
<?php
define( 'SCRIPT_DEBUG', false );
define( 'CONCATENATE_SCRIPTS', true );
}}}
This results in the following inline script being printed:
{{{
<script>
/* <![CDATA[ */
var heartbeatSettings = {"nonce":"7afd0d4e07","screenId":"customize"};
//# sourceURL=heartbeat-js-extravar _wpUtilSettings = {"ajax":{"url":"/wp-
admin/admin-ajax.php"}};
//# sourceURL=wp-util-js-extravar _wpCustomizeControlsL10n =
{"activate":"Activate & Publish","save":"Save &
Publish","publish":"Publish","published":"Published","saveDraft":"Save
Draft","draftSaved":"Draft
Saved","updating":"Updating","schedule":"Schedule","scheduled":"Scheduled","invalid":"Invalid","saveBeforeShare":"Please
save your changes in order to share the preview.","futureDateError":"You
must supply a future date to schedule.","saveAlert":"The changes you made
will be lost if you navigate away from this
page.","saved":"Saved","cancel":"Cancel","close":"Close","action":"Action","discardChanges":"Discard
changes","cheatin":"An error occurred. Please try again
later.","notAllowedHeading":"You need a higher level of
permission.","notAllowed":"Sorry, you are not allowed to customize this
site.","previewIframeTitle":"Site Preview","loginIframeTitle":"Session
expired","collapseSidebar":"Hide Controls","expandSidebar":"Show
Controls","untitledBlogName":"(Untitled)","unknownRequestFail":"Looks like
something\u2019s gone wrong. Wait a couple seconds, and then try
again.","themeDownloading":"Downloading your new
theme\u2026","themePreviewWait":"Setting up your live preview. This may
take a bit.","revertingChanges":"Reverting unpublished
changes\u2026","trashConfirm":"Are you sure you want to discard your
unpublished changes?","takenOverMessage":"%s has taken over and is
currently customizing.","autosaveNotice":"There is a more recent autosave
of your changes than the one you are previewing. \u003Ca
href=\"%s\"\u003ERestore the
autosave\u003C/a\u003E","videoHeaderNotice":"This theme does not support
video headers on this page. Navigate to the front page or another page
that supports video headers.","allowedFiles":"Allowed
Files","customCssError":{"singular":"There is %d error which must be fixed
before you can save.","plural":"There are %d errors which must be fixed
before you can save."},"pageOnFrontError":"Homepage and posts page must be
different.","saveBlockedError":{"singular":"Unable to save due to %s
invalid setting.","plural":"Unable to save due to %s invalid
settings."},"scheduleDescription":"Schedule your customization changes to
publish (\"go live\") at a future date.","themePreviewUnavailable":"Sorry,
you cannot preview new themes when you have changes scheduled or saved as
a draft. Please publish your changes, or wait until they publish to
preview new themes.","themeInstallUnavailable":"You will not be able to
install new themes from here yet since your install requires SFTP
credentials. For now, please \u003Ca href=\"http://localhost:8000/wp-admin
/theme-install.php\"\u003Eadd themes in the
admin\u003C/a\u003E.","publishSettings":"Publish
Settings","invalidDate":"Invalid date.","invalidValue":"Invalid
value.","blockThemeNotification":"Hurray! Your theme supports site editing
with blocks. \u003Ca href=\"https://wordpress.org/documentation/article
/site-editor/\"\u003ETell me more\u003C/a\u003E. \u003Cbutton
type=\"button\" data-action=\"http://localhost:8000/wp-admin/site-
editor.php\" class=\"button switch-to-editor\"\u003EUse Site
Editor\u003C/button\u003E"};
//# sourceURL=customize-controls-js-extravar _wpCustomizeNavMenusSettings
=
{"allMenus":[{"term_id":3,"name":"Primary","slug":"primary","term_group":0,"term_taxonomy_id":3,"taxonomy":"nav_menu","description":"","parent":0,"count":1,"filter":"raw"}],"itemTypes":[{"title":"Posts","type_label":"Post","type":"post_type","object":"post"},{"title":"Pages","type_label":"Page","type":"post_type","object":"page"},{"title":"Categories","type_label":"Category","type":"taxonomy","object":"category"},{"title":"Tags","type_label":"Tag","type":"taxonomy","object":"post_tag"},{"title":"Formats","type_label":"Format","type":"taxonomy","object":"post_format"}],"l10n":{"untitled":"(no
label)","unnamed":"(unnamed)","custom_label":"Custom
Link","page_label":"Page","menuLocation":"(Currently set to:
%s)","locationsTitle":"Menu Locations","locationsDescription":"Your theme
can display menus in 0 locations.","menuNameLabel":"Menu
Name","newMenuNameDescription":"If your theme has multiple menus, giving
them clear names will help you manage them.","itemAdded":"Menu item
added","itemDeleted":"Menu item deleted","menuAdded":"Menu
created","menuDeleted":"Menu deleted","movedUp":"Menu item moved
up","movedDown":"Menu item moved down","movedLeft":"Menu item moved out of
submenu","movedRight":"Menu item is now a sub-
item","customizingMenus":"Customizing ▸ Menus","invalidTitleTpl":"%s
(Invalid)","pendingTitleTpl":"%s (Pending)","itemsFound":"Number of items
found: %d","itemsFoundMore":"Additional items found:
%d","itemsLoadingMore":"Loading more results... please
wait.","reorderModeOn":"Reorder mode enabled","reorderModeOff":"Reorder
mode closed","reorderLabelOn":"Reorder menu
items","reorderLabelOff":"Close reorder
mode"},"settingTransport":"postMessage","phpIntMax":9223372036854775807,"defaultSettingValues":{"nav_menu":{"name":"","description":"","parent":0,"auto_add":false},"nav_menu_item":{"object_id":0,"object":"","menu_item_parent":0,"position":0,"type":"custom","title":"","url":"","target":"","attr_title":"","description":"","classes":"","xfn":"","status":"publish","original_title":"","nav_menu_term_id":0,"_invalid":false}},"locationSlugMappedToName":[]};
//# sourceURL=customize-nav-menus-js-extravar _wpMediaModelsL10n =
{"settings":{"ajaxurl":"/wp-admin/admin-ajax.php","post":{"id":0}}};
//# sourceURL=media-models-js-extravar pluploadL10n =
{"queue_limit_exceeded":"You have attempted to queue too many
files.","file_exceeds_size_limit":"%s exceeds the maximum upload size for
this site.","zero_byte_file":"This file is empty. Please try
another.","invalid_filetype":"This file cannot be processed by the web
server.","not_an_image":"This file is not an image. Please try
another.","image_memory_exceeded":"Memory exceeded. Please try another
smaller file.","image_dimensions_exceeded":"This is larger than the
maximum size. Please try another.","default_error":"An error occurred in
the upload. Please try again later.","missing_upload_url":"There was a
configuration error. Please contact the server
administrator.","upload_limit_exceeded":"You may only upload 1
file.","http_error":"Unexpected response from the server. The file may
have been uploaded successfully. Check in the Media Library or reload the
page.","http_error_image":"The server cannot process the image. This can
happen if the server is busy or does not have enough resources to complete
the task. Uploading a smaller image may help. Suggested maximum size is
2560 pixels.","upload_failed":"Upload failed.","big_upload_failed":"Please
try uploading this file with the %1$sbrowser
uploader%2$s.","big_upload_queued":"%s exceeds the maximum upload size for
the multi-file uploader when used in your browser.","io_error":"IO
error.","security_error":"Security error.","file_cancelled":"File
canceled.","upload_stopped":"Upload
stopped.","dismiss":"Dismiss","crunching":"Crunching\u2026","deleted":"moved
to the Trash.","error_uploading":"\u201c%s\u201d has failed to
upload.","unsupported_image":"This image cannot be displayed in a web
browser. For best results convert it to JPEG before
uploading.","noneditable_image":"The web server cannot generate responsive
image sizes for this image. Convert it to JPEG or PNG before
uploading.","file_url_copied":"The file URL has been copied to your
clipboard"};
var _wpPluploadSettings = {"defaults":{"file_data_name":"async-
upload","url":"/wp-admin/async-
upload.php","filters":{"max_file_size":"1073741824b","mime_types":[{"extensions":"jpg,jpeg,jpe,gif,png,bmp,tiff,tif,webp,avif,ico,heic,heif,heics,heifs,asf,asx,wmv,wmx,wm,avi,divx,flv,mov,qt,mpeg,mpg,mpe,mp4,m4v,ogv,webm,mkv,3gp,3gpp,3g2,3gp2,txt,asc,c,cc,h,srt,csv,tsv,ics,rtx,css,htm,html,vtt,dfxp,mp3,m4a,m4b,aac,ra,ram,wav,x-wav,ogg,oga,flac,mid,midi,wma,wax,mka,rtf,js,pdf,class,tar,zip,gz,gzip,rar,7z,psd,xcf,doc,pot,pps,ppt,wri,xla,xls,xlt,xlw,mdb,mpp,docx,docm,dotx,dotm,xlsx,xlsm,xlsb,xltx,xltm,xlam,pptx,pptm,ppsx,ppsm,potx,potm,ppam,sldx,sldm,onetoc,onetoc2,onetmp,onepkg,oxps,xps,odt,odp,ods,odg,odc,odb,odf,wp,wpd,key,numbers,pages"}]},"multipart_params":{"action
":"upload-
attachment","_wpnonce":"23c9ecbaaa"}},"browser":{"mobile":false,"supported":true},"limitExceeded":false};
//# sourceURL=wp-plupload-js-extra/* ]]> */
</script>
}}}
Note how the inline source comments cause the subsequent concatenated
script to be commented-out.
While this would be fixed by using multi-line comment syntax as noted
above, having these comments present when `CONCATENATE_SCRIPTS` is enabled
doesn't make sense. So it would make sense to potentially omit them when
`CONCATENATE_SCRIPTS` is enabled. But at the same time, #57548 proposes
the elimination of script concatenation altogether. Doing this would
eliminate some key technical debt which doesn't seem to be of any current
value, and to the contrary: there are clearly problems introduced by this
script concatenation.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/63887#comment:26>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list