Open msbt opened 4 years ago
First of all - how we can reproduce it? And what scripts do you expect to be loaded?
To reproduce, just fire up a (fresh) Wordpress installation, compare the scripts that were loaded before and after activating surveyjs.
Before (9 queries, 159,16 KB):
After (54 queries, 3,08 MB): ...
As for the scripts that I expect to be loaded: This is not a page where surveyjs is activated, so technically none. If there would be a survey on a page, only the ones that came with surveyjs should be loaded, since all required ones are included there. None of the WordPress dist files are required I reckon.
Looking at this long list I see the only SurveyJS script - "survey.jquery.min.js". Other scripts are neither related by SurveyJS library (excluding jQuery script) nor mentioned in SurveyJS wordpress plugin code. Most likely this question is not related to SurveyJS and should be asked in Wordpress community.
that's what I meant, something in the surveyjs plugin loads all those scripts even though they're not needed, that shouldn't happen.
there are a few plugins with the same issue, maybe the gutenberg implementation is to blame?
https://wordpress.org/support/topic/plugin-loads-a-lot-of-js-files-in-frontend/ https://wordpress.org/support/topic/loading-all-js-in-wp-includes-js-dist/
I'd like to say that the loaded scripts are not mentioned in the plugin code.
I've checked these issue and both of them have no answers.
In case of any wordpress option control this bloating scripts loading exists we'll definitely use it in our plugin code.
ok more hopefully useful links:
https://blog.futtta.be/2019/03/22/how-to-not-correctly-load-gutenberg-js/ (and a follow up from that https://blog.futtta.be/2019/03/18/developers-dont-make-gutenberg-go-badass-enberg-on-my-frontend/ where it says don’t declare wp-blocks, wp-element
)
https://richtabor.com/has-blocks-gutenberg-scripts/
If you are using the source code of SurveyJS Plugin in your Wordpress instance, could you try these approoaches on your side?
I'm not that kind of developer, but I'll give it a try and keep you posted.
I already can tell you that if I remove the gutenberg functionality (since I'm not using the gutenberg editor) with commenting the register_sjs_gutenberg_block
function, is shows only the js files needed.
I was wondering why there were so many js files being parsed on my WP site and figured, that if the surveyjs plugin gets activated, all the included js files in the WP dist directory are being loaded. Usually only enqueued scripts should be added, but as soon as surveyjs is activated, all (!) of them are included.
I did a bit of digging and found this post where the last post identifies
register_block_type
as the culprit. I did a quick search and found that the correcteditor_script
is used. Any idea what else might cause that?Best regards, Matthias