Conflicting js script in latest update
-
Yesterday’s update seems to have created a conflict with Autoptimize.
Query Monitor reports: Uncaught JSMin_UnterminatedStringException, followed be a lengthy amount of code that references errors in a .js file in the Google Site Kit plugin.
Deactivating Site Kit cleared the errors.
-
Hi @sirstuey, thanks for reaching out. I’d be happy to look into this further for you. On my initial checks with Autoptimize, I am unable to replicate your issue. To investigate this further, please can you share the following:
- Your Site Health information. You can use this form to share privately if preferred.
- A recording or screenshot of this with the console error included so that I can see where this is happening.
- Do you see the error when deactivating Autoptimize but keeping Site Kit active?
You could also try disabling your Autoptimizie settings to see if this is related to a specific setting in the plugin which would help us to better understand the issue. If you have any other questions at this time then let me know. I will continue to run checks on this while awaiting your feedback.
Thank you – I shared a screen capture and also the text of the error.
It’s a strange one – Query Monitor is appending the error code to the bottom of all pages. Normal QM functions are no longer available with Site Kit activated and the error messaging rendered.
Everything was working fine. Google Site-Kit rolled out an update. That evening I noticed the error code at the bottom of all of my pages when signed in as admin. I only noticed because some of the longer strings created a horizontal scroll bar.
The error messaging specifically references a Google Site Kit .js file. It’s not clear to me why Query Monitor functionality fails when the error is shown.
The error also disappears when Autoptimize is disabled, which was expected.
If the JS minifier in AO bows out ungracefully on a JS file, then excluding that JS file (or all of
wp-content/plugins/google-site-kit/should help.For the developers; AO only tries to minify files that are not minified as per the filename (xyz.js will go through minification, xyz.min.js will not), is there any reason why you do not use the .min.js suffix, as the files are minified OK?
@sirstuey Thanks for all the information you have shared. As stated above by @optimizingmatters, you can use an exclusion rule to exclude:
wp-content/plugins/google-site-kit/After applying this you should no longer see the issue. If you continue to see this or have any other issues or questions then please let me know.
Thanks! I tried adding exclusions when I thought it was Google ad units causing the problem. Will give this a try if I reactivate Site Kit.
Since this only started happening with the latest Site Kit update, do you think this is unique to my install, or a bug that needs to be worked out on Google Site Kit’s end?
@sirstuey This shouldn’t be related to the latest version of Site Kit as nothing has changed within it that would have an impact on this so this is unknown as to why this happened after the update.
We will be sure to check this to ensure there isn’t anything on our side but we don’t believe that to be the case.
As we didn’t receive a response I’ll mark this as resolved. Feel free to open a new support topic if you continue to encounter issues, or reopen this topic and we’d be happy to assist.
No, it has not been resolved.
The issue seems to involve Autoptimize and Google Site Kit, and Query Monitor’s error reporting. It only started after Google Site Kit was last updated, and a specific Site Kit js file is the only one called out in the error code.
Adding wp-content/plugins/google-site-kit/ to the Autoptimize exclusions list and clearing its cache did NOT work.
The error only presents in the admin view, via Query Monitor appending it to the bottom of pages.
The file specifically called out in the error was modified on 7/14, presumably with the latest update – googlesitekit-vendor-[string redacted in case it’s unique].js .
1.182.0: NO error
1.183.0: ERRORHere’s what I did:
Deactivated Site Kit. Renamed folder to old-
Uploaded and activated 1.182.0.
Result: NO Error. Query Monitor is accessible, nothing is appended to the bottom of content pages.Deleted 1.183.0
Deactivated and deleted 1.182.0Reinstalled 1.183.0 via WP Add Plugin in dashboard, and activated.
Result: ERROR appended to all content pages.Deactivated and deleted 1.183.0 again.
Uploaded and activated 1.182.0 again. No error.It seems that 1.183.0 introduced an error or conflict with Autoptomize that breaks Query Monitor.
@sirstuey Thanks for confirming. If possible at all, it would be useful to get a recording of you taking those steps so that I can share it with the team. I will perform some further testing on this to try and replicate the issue which I have been unable to thus far.
Please feel free to share any recording to the private form you shared previously. Once I have an update on my troubleshooting then I will update this thread.
Thanks you, uploading now.
It’s a little tedious, as the folder upload and deletion steps took some time, but it shows what happens with 1.182, 1.183, and back to 1.182.
@sirstuey Thanks for your patience while I investigated this further and thanks for the detailed report, and especially for narrowing it down to 1.183.0. That was exactly the right clue and it led us straight to the cause.
You’re not doing anything wrong here, and it isn’t really an Autoptimize bug either. Starting in 1.183.0, one of Site Kit’s JavaScript files (
googlesitekit-vendor-….js) got much larger and began including code that Autoptimize’s built-in minifier can’t parse. When Autoptimize tries to re-minify that file it fails with theJSMin_UnterminatedStringExceptionyou saw, and that error text is what gets dumped onto the page and breaks Query Monitor’s output along the way.We’ve reproduced this on a clean test site and confirmed the cause. A proper fix on our side is in progress.
In the meantime, here’s a reliable workaround. Site Kit’s JavaScript is already minified when we build it, so telling Autoptimize to skip our files costs you nothing in performance:
add_filter( 'autoptimize_filter_js_exclude', function ( $exclude ) { $addition = 'google-site-kit/dist/'; return empty( $exclude ) ? $addition : $exclude . ', ' . $addition; } ); add_filter( 'autoptimize_filter_css_exclude', function ( $exclude ) { $addition = 'google-site-kit/dist/'; return empty( $exclude ) ? $addition : $exclude . ', ' . $addition; } );You can add this with a code snippets plugin, or as a small custom plugin — a file in
wp-content/mu-plugins/works well. After adding it, clear the Autoptimize cache.We tested this exact snippet against Site Kit 1.184.0 with Autoptimize and confirmed it stops the error. Let me know if you have any issues with this.
Thank you!
I installed 1.184.0 (via WP Add Plugin), and when I attempted to add the exclusion code to my functions file, it created an error that ERASED the functions file, to 0B. This is the error it gave:
Unable to communicate back with site to check for fatal errors, so the PHP change was reverted. You will need to upload your PHP file change by some other means, such as by using SFTP.
After recovering the file from my backup, I tried again, and it did the same.
I recovered the file again and added the exclusion code via SSH, cleared the Autoptimize cache, and the error persisted on live pages. I tried again with a refresh. The error persisted.
At this point I wasn’t about to check whether moving the snipper from my functions file to mu-plugins would change anything, as dealing with file recovery was headache enough. The exclusions via Autoptimize didn’t work the other day either, maybe for similar reasons.
I tried editing and saving a different theme functions file, and WordPress wiped that one clean too.
I disabled the plugin, edited my functions file, and it saved properly.
I can’t even begin to understand how this can be related. The Site Kit and Autoptimize issue breaks Query Monitor on the admin front end. But this is the WordPress Dashboard.
Just to be sure, I repeated the process. Deleted the plugin. Created a new theme functions .php file and wrote just a comment. Edited within WP. “File edited successfully.”
Added and activated Site Kit 1.184.0 again.
Went back to my test functions file. Modified the comment. Tried to save it. Again, the file was completely erased as WordPress “reverted it.”
Reverted back to 1.182.0 again. No error, no files being erased when I try to save.
I guess my 2 questions are:
1) Are there other ways I can force exclusion so as to avoid the Site Kit error?
2) How would v 1.184.0 be tied to the error that erases any theme files that I attempt to edit via the WordPress theme file editor?
Unable to communicate back with site to check for fatal errors, so the PHP change was reverted. You will need to upload your PHP file change by some other means, such as by using SFTP.
Could there be a different conflict between Site Kit and something else to result in this error? This could be a coincidental unique-to-me error, but I’ve never seen it before, and it went away when I removed 1.184.0 . (I have other WP file editing errors, due to manually uploading via root vs. account name, but that’s known to me. This issue affected account-owned files that are otherwise editable when 1.182.0 is active or disabled.)
@sirstuey Sorry to hear that you’re still encountering an issue when implementing the code shared previously. Could you please try downloading this mini-plugin, installing on your site and activating and let me know if this resolves the issue for you?
You must be logged in to reply to this topic.