• Resolved nesoor

    (@nesoor)


    Hello WordPress memebers,
    All of my CSS in the customizer will be placed in the header as inline CSS.
    I personally do not find this necessary since it will only slow down the performance of my website. I was hoping that there is a way to output the customizers CSS in a stylesheet ??

    • This topic was modified 5 years, 3 months ago by nesoor.
Viewing 10 replies - 1 through 10 (of 10 total)
  • Is it a lot of CSS?
    You might come to the same conclusion for each page of your web site. The HTML of the page will be the same each time it is generated, yet the theme does that each time a visitor views the page. If it’s in a file, it would be faster, right? Well, there are caching plugins that do this for you.

    For a little bit of CSS, there is no real benefit to putting it in a file (even if the browser would cache the file).
    For a big amount of CSS, you could make a child theme and put it in the child theme style.css file. It’s a trade-off since the child theme files have to be loaded in addition to the parent theme files.

    or just use a caching plugin

    Thread Starter nesoor

    (@nesoor)

    Hey Joy,

    Thanks for your reply!

    I know there are certain caching plugins and that I could use a child theme or even install a plugin that can easily add this functionality.

    Why I still want the customizer to output the CSS in a stylesheet is because I manage a lot of websites and this option would make it so much easier and faster for me to do my work.

    Many of my clients also manage their website themselves so over the years I have installed a caching plugin that is easily manageable and doesn’t interfere with other software installed on the website.

    That is why I was hoping I could maybe do a small change to the functions.php to output the customizers CSS in a stylesheet. Would save me a lot of work in the future ??

    because I manage a lot of websites and this option would make it so much easier and faster for me to do my work.

    This is totally different from your first question, when you said it was about performance.

    I personally don’t see any benefit of having the styles in a file. It wouldn’t make the site faster, and it wouldn’t make your work faster.
    It would complicate the interactions with the Customizer (for changesets and draft previews) and export/import plugins.
    The Additional CSS is only intended for small things. If there is a lot of CSS, it should be in a child theme.

    Thread Starter nesoor

    (@nesoor)

    Hey Joy,
    I appreciate that you are taking the time to comment and give me advice but you are not really answering my question ??
    My question is whether it is about performance or not and if it is possible to output the customizers CSS in a stylesheet.

    Moderator bcworkz

    (@bcworkz)

    It’s actually faster to have it inline. Think about it. It’s the same volume of data either way. But as a separate file, the browser must fetch an additional file. Added external files are part of what drags down page load speeds. In speed optimization recommendations from Google, they suggest all CSS be inline. Of course they also want us to only place applicable CSS for the current page. WP CSS usually contains a lot of non-applicable CSS.

    Some optimization plugins will combine the CSS from external files and inject them inline to improve performance.

    If you want to use another external file for additional CSS without doing a child theme, I suggest enqueuing such a stylesheet from a site specific plugin. Yes, it’s little different than a child theme, but it’s still a good container for any other custom work you need for a particular site. Some themes are installed as a child, preventing that option anyway. Adding a plugin is always possible.

    This is still better than writing an external file from the customizer. I assume your thought is to still utilize the UI to make CSS alterations, but then avoid all the messy inline styles by packaging such content into a file. This would need to be done dynamically on every page request. And it’s still an added external file. Plus added processing on every request. This is not an efficient use of resource. Additionally, you could encounter a race condition where the browser if trying to fetch the file before the server is finished writing. I advise against such a scheme.

    But to answer your question, it should be possible by interrupting the inline output process and instead output a file reference. Another bit of code grabs the data from theme mods and writes to a file. I’m unsure of the specifics though, and that race condition is still possible.

    Thread Starter nesoor

    (@nesoor)

    Hey bcworkz,
    Thanks for your reply!
    Do you think it will be easy to change this? Also will it cause any problems in the future ? I also saw this code WP_Customize_Code_Editor_Control but I am not sure how it works. So far as I know I can use the wp customize code editor to implant my own CSS editor.

    Another bit of code grabs the data from theme mods and writes to a file.

    Only the ID is stored in theme_mods. The CSS itself is stored in a custom post type: custom_css.

    Moderator bcworkz

    (@bcworkz)

    If you plan is to alter that class, then yes, there will be future problems. You could override its methods in a class extension. But how you would get WP to use your class I couldn’t say. You’d need to find a filter that lets you substitute your own class. I’d be surprised if such a filter exists.

    Thx Joy, I skipped over a major step there!

    Thread Starter nesoor

    (@nesoor)

    Hey Joy and BCWorkz,
    Thanks for all the advice.
    I thought about it and I also checked the Google page speed test results and as you guys already said it wouldn’t really matter whether its in a stylehseet or inline the page speed would stay the same. So I decided to use the basic customizer instead and not change it. Thanks!

    Moderator bcworkz

    (@bcworkz)

    You’re welcome!

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘Customizer CSS in a Stylesheet’ is closed to new replies.