jQuery file truncation - pagespeed breaking javascript files

171 views
Skip to first unread message

Shane Marsh

unread,
Jan 10, 2020, 4:41:21 AM1/10/20
to mod-pagespeed-discuss
Hiya, 

I have a strange one. We have an issue that emerged whereby pagespeed has been optimising jquery.js and breaking it - it's as if it's hitting some sort of character limit and then simply stopping mid way through. 


We couldn't find a way of resolving it and so we disallowed that file but the issue has moved onto another. This file was OK before and now it seem to be breaking: https://www.cja-aesthetics.co.uk/wp-content/plugins/wpforms/assets/js/jquery.validate.min.js becomes: https://www.cja-aesthetics.co.uk/wp-content/plugins/wpforms/assets/js/jquery.validate.min.js,qver=1.19.0.pagespeed.jm.sNmr_qra70.js. Again the file is heavily truncated and broken. 

Whats going on?
Shane

Shane Marsh

unread,
Jan 10, 2020, 6:00:57 AM1/10/20
to mod-pagespeed-discuss
Yep were out of ideas - not even https://www.cja-aesthetics.co.uk/fat-dissolving-injections/?PageSpeedFilters=+debug tells us anything :(

Shane

Longinos

unread,
Jan 10, 2020, 5:31:28 PM1/10/20
to mod-pagespeed-discuss
Hi Shane

Seems that jquery is included 2 times, allmost when I have tested the page:

Have you tried to delete the version info? I will say, the files have the ?ver= thing in it. If files are optimized by pagespeed, don´t need the version info
as far as when file changes, the hash that pagespeed uses changes too.

Or maybe the files get truncated when a flush end without combine all the file or maybe the max combine size is small.
As a test, try to disable js combine filter.

Shane Marsh

unread,
Jan 13, 2020, 4:26:45 AM1/13/20
to mod-pagespeed-discuss
Hi Longinos, thanks for coming back to me. 

Well this certainly is happening as result of a change I made to the pagespeed config before christmas but so far not worked out what it is. I will check the max combine size as it's very strange and it's happening only on some sites with the same configuration not all.

I'm not sure why we have two jqueries (i'll look into that) but the one from wp-includes is currently on pagespeed disallow to stop the whole site breaking.

Shane :)

Shane Marsh

unread,
Jan 13, 2020, 6:26:00 AM1/13/20
to mod-pagespeed-discuss
Well I can tell you it's absolutely none of those ideas and I'm totally baffled. I even attempted a full system restart in the middle of the day to try and solve this but no luck. 

Also It's worth noting that errors are creeping in. If I disallow jquery.js it clears the issue on some sites (such as CJA Aesthetics) but creates strange issues on other sites. For example https://smithandsmith.co.uk/ currently has VM2437:1 Uncaught ReferenceError: mod_pagespeed_AZPcVqr79d is not defined - this is very worrying and if I can't contain the breakage then we will have to consider our use of pagespeed altogether. 

Any ideas are welcome.

Shane Marsh

unread,
Jan 13, 2020, 7:39:06 AM1/13/20
to mod-pagespeed-discuss
OK I've got it to a point (I think) where sites are stable. No idea what is causing this but I feel the issue might be unique to us. 

Does mod_pagespeed have any dependencies that can be updated by apt-get; particularly dependencies that might relate to javascript minification? After a lot of tweaking things now seems to be stable provided I disallow jquery.js but the minification always breaks at the same point. We have not updated Nginx or pagespeed versions in months but something has changed.

Shane 

Longinos

unread,
Jan 13, 2020, 12:58:34 PM1/13/20
to mod-pagespeed-discuss
Hi Shane
Well....
As far as I know pagespeed don´t have any external dependencies, all is staticaly linked in the module.
Uncaught ReferenceError: mod_pagespeed_AZPcVqr79d This messaje is related to js_defer (defer_javascript filter). This filter names combined files and snipets with such names and then execute it, so some function call to a function that is not defined..... seems related to the order the javascript is loaded.

And the js minification pagespeed does is very conservative, so if it processes an already minified file, do nothing (maybe cache extend).

Can be a cloudflare issue? Whats happens whe you hit the server directly, by passing cloudflare?
Also can be a defer_javascript issue, try to disable this filter.

Related to  pagespeed MaxCombinedJsBytes MaxBytes; the default value of Maxbytes is 92.160 (90Kb)so accordling with the docs, any file wiht upper size thatn that is let allone, jquery has 94.6Kb.
Maybe lowering the MaxBytes you can assure the jquery is let alone.

Combine filters work on flush windows, start to combine files but when a flush in the page is done, end the combine work and start with the next file.

When you combine js files, in some way you lost the control on what order the files are loaded, and in some scenarios the order matter, jquery is a good example.
You can´t load a file that depens on jquery before the jquery loads or get a error that say jquery not defined.
In other hand when you defer the js files they are executed in the order they are in the html, but, I think, the filter defer_javascript is not a good solution to defer js, and in th docs is stated as a higth risk filter.

Shane Marsh

unread,
Jan 14, 2020, 6:06:21 AM1/14/20
to mod-pagespeed-discuss
Well I have to say after trying all of these suggestions and a lot more I can't find anything that works. I've rolled back wordpress plugins, scripts we've added, configuration changes, cloudflare and I've made countless restarts - nothing helps. I have attached a copy of our Nginx config file incase I'm missing something but this problem has been with us for a week now and it makes no sense whatsoever! How can something break and break this badly without a reason!?! 

Shane
setup.conf

Longinos

unread,
Jan 14, 2020, 7:17:00 AM1/14/20
to mod-pagespeed-discuss
Hi Shane
The issue is when you "enable" pagespeed for jquery, rigth?
Have you modified this WP?
For me sounds strange that jquery file has the -wp at the end, normaly WP uses jquery.js?ver=X.XX.XX w/o the trailing -wp.

Whit the jquery disallowed, the page works w/o error, all most for me.
The only messages in devtools console are about cookies and SameSite related to cross-site request.....  and the site don´t seem to be broken.

Have you tried to lowering the pagespeed MaxCombinedJsBytes MaxBytes;?
I see that the biggest combined file size is 76.9Kb so you may try to set:
pagespeed MaxCombinedJsBytes 81920;
80Kb max size of combined js files, this must leave jquery alone, same that html2canvas.min.js file now.

And one more thing... try to clear pagespeed cache when you make changes in config and restart.
If the cache has stored a corrupt file, this file is served until it need to refresh.

For me, and at a first view, the config file look good.

I can´t use /?PageSpeedFilters=+debug cause it has many redirect, Maybe you need to explicit disable the noscript filter, cause your site can´t work w/o javascript don´t need it.

pagespeed SupportNoScriptEnabled false;

Shane Marsh

unread,
Jan 14, 2020, 7:35:06 AM1/14/20
to mod-pagespeed-discuss
Hiya, 

To be honest, I'm going to have to debug this in some other way because I've just been called in from my lunch after a load of clients complaining that their websites are broken. jquery not defined. I have tried lowering MaxCombinedJsBytes but that had no effect. I have to be very careful about constantly clearing the pagespeed caches because it puts the servers under a very high load and can lead to websites becoming unresponsive.

I've never known anything like this but we cannot afford to debug this on production servers any longer. What a mess. I'm trying to turn all the Javascript filters off now just to try and get a site to load correctly.

Shane

Longinos

unread,
Jan 14, 2020, 10:57:32 AM1/14/20
to mod-pagespeed-discuss
Hi Shane
Sorry if I can´t be of more help.....

Shane Marsh

unread,
Jan 14, 2020, 11:13:03 AM1/14/20
to mod-pagespeed-discuss
Hi,

We'll I think some of our issues were compounded by damaged files being stuck in cache and then somehow combined with other javascript files. We also think that the wordpress jquery file had become slightly corrupt. I only say that because I tested the original jquery.js file from within wp-includes and in some syntax checkers it came back with issues. Anyways we have replaced the Wordpress jquery with the same version from github. I have all pagespeed javascript/jquery filters switched off and apart from one site which completely fell apart (now resolved happily) things have quietened down. No nearer to finding out whats happening but at least things are "stable" for now. To go back to an earlier comment, I don't know what the -wp bit is in the version number. Is that not supposed to be there?

Shane 

Longinos

unread,
Jan 14, 2020, 4:48:46 PM1/14/20
to mod-pagespeed-discuss
Hi Shane

Is the 1st time I see the -wp, but googling for it I found that is a patched version, with updates from the jquery version 3.4.0. Is new from the WP version 5.2.1
I use a theme that don´t need jquery and the only page I use it is a form contact, plus use Jquery updater that loas the lates version of jquery, 3.4.1 now.
and before use the jquery updater plugin I have this in my child theme functions.php:

add_filter( 'style_loader_src', 'generate_remove_cssjs_ver', 10, 2 );
add_filter( 'script_loader_src', 'generate_remove_cssjs_ver', 10, 2 );
function generate_remove_cssjs_ver( $src ) {
if( strpos( $src, '?ver=' ) )
    $src = remove_query_arg( 'ver', $src );
    return $src;
}

SUNIL GUPTA

unread,
Jan 16, 2020, 12:58:19 AM1/16/20
to mod-pagesp...@googlegroups.com
stop email

--
You received this message because you are subscribed to the Google Groups "mod-pagespeed-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mod-pagespeed-di...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/mod-pagespeed-discuss/6494f0ed-e635-457d-876d-5e87ffaff958%40googlegroups.com.

Shane Marsh

unread,
Jan 16, 2020, 5:30:36 AM1/16/20
to mod-pagespeed-discuss
Even more strange things are happening today. I commented out three javascript filters rewrite_javascript, defer_javascript & combine_javascript but over the last 24 hours I noticed these filters on some sites were still ACTIVE so today I explicitly disabled and them and the filters will still NOT switch off! At this rate I'm going to go totally insane. I don't see any other option but to re-compile Nginx on both servers? Total disobedience. 

Shane

Shane Marsh

unread,
Jan 16, 2020, 5:45:20 AM1/16/20
to mod-pagespeed-discuss
Ahh it seems pagespeed will never leave a file alone. Even with the filters switch off pagespeed still passes the file and adds a .pagespeed file extension with a hash. Confusing. 

Shane

Longinos

unread,
Jan 16, 2020, 7:26:07 AM1/16/20
to mod-pagespeed-discuss
Hi Shane
Maybe is the cache extender filter. It add the pagespeed stuff to the url like:
url.pagespeed.ce.HASH.file-extension
Note the ce.

Shane Marsh

unread,
Jan 16, 2020, 7:41:34 AM1/16/20
to mod-pagespeed-discuss
Yes! All the URLs do have CE in them as you say. 

Thanks again.

Shane :)
Reply all
Reply to author
Forward
0 new messages