Magento 2 Module Load Order Position

This tutorial will explain the Magento 2 Module Sequence – load order position which will show you the right load order in your component’s/ module’s module.xml file. If you want to understand the dependencies among the components using your component’s composer.json, for that you need to understand the exact load order in your component’s module.xml file using the <sequence> tag.

What is the <sequence> tag?

The responsibility of the <sequence> tag is telling you that what components have to be loaded before the current component is loaded for the current request. The <sequence> is especially supported when you implement the loading of different types of file such as configuration files, view files (including CSS, LESS, and template files), or setup classes.

In addition, if you need to load the regular classes (non-setup classes), there is no influence of the <sequence> tag on that implementation.

Note: The classes are called as setup classes when they are included by the component that creates or updates database schema or data. Rest are non-setup classes.

If you want to run your project fluently, you should use composer.json and <sequence> in module.xml file if you are ensuring that your needed component’s logic rely upon another component.

Module Sequence Cases:

For example, there are Component/Module A and Component/Module B. Suppose that Component A introduces clothlayout.xml, which allows updating block clothBlock from component B. At that time, you need to clarify that in component B’s <sequence> entry in module.xml file. So now we will start with component A which needs a configuration file from component B.

Case 1: The files, which come with the same type, will be loaded from various components while the sequence information in each component’s module.xml file are considered as well.

Case 2: Suppose that you need to load a list of the layout files with the name default.xml and component A designates component B in <sequence>. The following is the load order of the files:

  • component X /view/frontend/layout/default.xml — Either we don’t care about when component X loads or perhaps component B requires it to be loaded before it.
  • component B /view/frontend/layout/default.xml
  • component A /view/frontend/layout/default.xml —Loads after component B because component B is listed in component A’s tag.
  • component Z /view/frontend/layout/default.xml — Either we don’t care about the sequence for component Z or perhaps component Z requires component A files to be loaded before it.

In <sequence> tag, you need to mention any valid component without any limitation and you need to be sure that the component is declared in the require section of the composer.json file.

Leave a Reply