Skip to content
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

JS + CSS should not be loaded on every page #35

Closed
dd32 opened this issue Jan 5, 2023 · 4 comments · Fixed by #255
Closed

JS + CSS should not be loaded on every page #35

dd32 opened this issue Jan 5, 2023 · 4 comments · Fixed by #255
Labels
bug Something isn't working priority: low
Milestone

Comments

@dd32
Copy link
Member

dd32 commented Jan 5, 2023

As currently expected, the wporg-two-factor settings screen CSS/JS is loaded/output on every page.

$ curl -is https://wordpress.org/ | grep wporg-two-factor

<style id='wporg-two-factor-settings-style-inline-css'>
.wp-block-wporg-two-factor-settings h3 {
.wp-block-wporg-two-factor-settings .components-button {
<script src='https://wordpress.org/wp-content/plugins/wporg-two-factor/settings/build/script.js?ver=1672716006' id='wporg-two-factor-settings-script-js'></script>
@iandunn iandunn added this to the Iteration 1 milestone Jan 5, 2023
@iandunn
Copy link
Member

iandunn commented Jan 5, 2023

I ran into this as well :(

d8e6a9a may help some, but doesn't solve it on by itself.

IIRC Gutenberg solved this problem automatically in WordPress/gutenberg#5445 and some of the related issues, but maybe that's not working for us because we aren't loading it via post_content ?

@iandunn iandunn added the bug Something isn't working label Jan 5, 2023
@dd32
Copy link
Member Author

dd32 commented Jan 6, 2023

d8e6a9a may help some, but doesn't solve it on by itself.

I suspect that would actually make it worse, as they'd now be loaded too, although It doesn't look like that's happening..

IIRC Gutenberg solved this problem automatically in WordPress/gutenberg#5445 and some of the related issues, but maybe that's not working for us because we aren't loading it via post_content ?

If it was solved through Gutenberg, not using post_content would work in the reverse than what it's currently doing - I'd expect the block assets to never be loaded.

It looks like we can switch to viewScript in block.json to get the script loaded only when rendered, but for styles there's nothing there... See viewStyle in WordPress/gutenberg#41236

@dd32
Copy link
Member Author

dd32 commented Feb 17, 2023

Turns out this is also causing zxcvbn.min.js and qrcode-generator/qrcode.js to be enqueued.

https://meta.trac.wordpress.org/ticket/6770

dd32 added a commit that referenced this issue Feb 17, 2023
dd32 added a commit that referenced this issue Feb 22, 2023
Restore `viewScript` support for non-gutenberg blocks by removing the array item before Gutenberg processes it badly.

Reverts 169a0c4

See #35
@adamwoodnz
Copy link
Contributor

Update: All that remains is the CSS now

$ curl -is https://wordpress.org/ | grep wporg-two-factor

<link rel='stylesheet' id='wporg-two-factor-settings-style-css' href='https://wordpress.org/wp-content/plugins/wporg-two-factor/settings/build/style-index.css?ver=0.1.0' media='all' />

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working priority: low
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants