- This topic has 15 replies, 3 voices, and was last updated 2 years, 2 months ago by David.
-
AuthorPosts
-
July 19, 2022 at 12:22 am #2286977Rostyslav
Hello,
I would like to know if when I use WordPress Gutenberg Block in page A. And in page B I dont use Gutenberg. Will wordpress load the css from page A on Page B or on other pages? In other words, will wordpress load the Gutenberg Css on a page that I am using it or that css will be loaded on all pages of a website?
I am combining Generateblocks with some WordPress default Gutenberg blocks. As I know, generateblocks use dynamic CSS. But I dont know if that is a good practice combining them. I just want to load all my css dynamically on pages where it is just used.
Thanks!
July 19, 2022 at 12:40 am #2286997Fernando Customer SupportHi Rostyslav,
Some WP Block settings like text color are added inline, which means it’s not loaded in other pages.
WordPress however loads a stylesheet for all pages for WP Blocks. It can be dequeued though if you want: https://smartwp.com/remove-gutenberg-css/
Hope this clarifies!
July 19, 2022 at 12:56 am #2287014RostyslavHello,
I know that Customizer Css is loaded in all pages. But if I use just Gutenberg block styles that are in the editor without additional Css, does it also load all that CSS in all pages?
What is your recomedation as best practice to get the fastest website? Only using Generateblocks?
July 19, 2022 at 1:16 am #2287027Fernando Customer SupportYes, that’s what I meant; not Additional CSS.
WordPress loads a stylesheet style.min.css which has CSS for its Blocks on all pages even if no WP Block is used in the editor.
If you use a WP Block, there’s also CSS added in-line, so if you’re not using WP Blocks, those in-line CSS wont be added, but the stylesheet will still be there.
Not using WP Blocks will reduce inline CSS so that may be a bit faster. If you dequeue the stylesheet, that may help as well. If you’re using an Optimization plugin, you can probably try removing unused CSS as an alternative, though this sometimes causes issues as well.
July 19, 2022 at 2:02 am #2287062RostyslavJust last question. If for example I use WordPress image block and there are many integrated features like border radius that adds this CSS (not inline)
.wp-block-image.is-style-circle-mask img, .wp-block-image.is-style-rounded img, .wp-block-image .is-style-rounded img { border-radius: 9999px; }
Will this css be loaded in all pages of my site or just in this particular page (not inline css)?
July 19, 2022 at 5:32 am #2287203DavidStaffCustomer SupportHi there,
WP will load its block-library CSS on every page including that.
July 19, 2022 at 6:07 am #2287228RostyslavThanks
July 19, 2022 at 6:27 am #2287257DavidStaffCustomer SupportYou’re welcome
July 19, 2022 at 6:44 am #2287273RostyslavHi again! How can I load wordpress block styles, if and only if the block is present on the page?
Any tip or php rule?
July 19, 2022 at 6:54 am #2287282DavidStaffCustomer SupportThis article explains:
https://make.wordpress.org/core/2021/07/01/block-styles-loading-enhancements-in-wordpress-5-8/
But i would recommend reading the Comments left by Tom and I.
TLDR: The method WP choose to use means loading the styles in the Footer. Unless you use an optimizer to scrape those styles and add them to the head, you will most likely experience CLS.July 19, 2022 at 7:15 am #2287302RostyslavTo complicated for me. I am going to leave it as it is.
Another question. As I know Generateblocks use dynamic CSS true? But if I give a custom class to a GB container and then add CSS in a customizer for that class, that CSS is loading in all pages. How can I also load that custom CSS that I add to Generateblocks blocks dynamically?
1) Create hook with
<link rel="stylesheet" src="style.css">
for all pages separately2) Any tip?
July 19, 2022 at 7:33 am #2287329DavidStaffCustomer SupportAs I know Generateblocks use dynamic CSS true?
That is true.
Theres no easy way to do that, you would have to parse the entire page checking for existence of that class, and that would happen on every page. So it really is not worth doing. You would be better to either:
a. put the CSS in a child theme stylesheet. So the browser can cache that file on first load.
b. use a cache plugin to combine the CSS files into a cacheable file.July 19, 2022 at 8:43 am #2287567RostyslavHello!
Can you check if I did it properly. Link in private area.
July 20, 2022 at 2:03 am #2288184DavidStaffCustomer SupportSo the Additional CSS is no longer inline in the
<head>
of your site, i can see it is now in an autoptimize file.
And those files are being cached by the browser.July 20, 2022 at 3:39 am #2288245RostyslavThank you!
-
AuthorPosts
- You must be logged in to reply to this topic.