I'm looking for some BEST PRACTICES insight into using page_layout.xml. Is it a good idea to try and decouple the non-shared resources on Product Pages, Category Pages and CMS Pages? If so, what's the best way to do this? Recently found myself creating a bunch of CMS specific CSS rules for our CSM pages and I knew the CSS rules may continue to grow a bit so I decided to create a dedicated layout file (Magento_Theme\page_layout\cms_layout.xml). To achieve this, I created a new page_layout but also had to make a plugin beforeRenderResult() to load in in <body> BOTH the standard class page-layout-2columns-left and the new class page-layout-cms-layout. If I didn't do this, I would have had to modify a lot of CSS.

Some of the benefits I think I'm realizing are:

  • (Maintenance) I no longer have to manage a lot of Content > Page > Design > Layout Update XML content. I can just change the "Layout" dropdown to the CMS Specific Layout.
  • (Slight Performance) I don't have to load the CSS for the CMS pages on the Product Pages and Category Pages

Next up - might be to look at some of the heavy UI JS/CSS being used on Product Pages and not have that being loaded on Category Pages? Does this situation make sense to experiences Magento Developers OR should I provide more clarity?

I'm pretty certain I'm not making any big performance gains with this particular situation but I am curious whats "Best Practice". As it stands, it seems like Magento load the the entire websites resources on every page, no matter how big or small (Category JS/CSS, Details JS/CSS, Checkout JS/CSS, etc). I'm not sure that's great either.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.