:::: MENU ::::

Magento Tutorial | Magento Blog | Learn Magento 2

Cookies Consent Popup

basically shim is used to avoid dependency conflict. 

For example if you calling a **custom javascript** then it must be loaded after javascript library isn't it? but magento doesn't know whether the library is loaded or not. So using shim we'll let system know that it is dependent on **library** so it will be instantiated when we map shim.

And

Magento uses requirejs to speed up the stuffs and (asynchronously module dependencies) nature of require js. So we use shim to tell the machine load our defined dependency first i.e., **jquery**

If we don't define then we get **jquery not defined error** while developing custom extensions as well.

The RequireJS shim configuration directive allows you to configure what I’ll call “load order” dependencies. i.e., you can say

when you load the jquery.cookie module? Make sure you’ve completely loaded the jquery module first. 


**Example :**

    var config = {

    paths:{

        "jquery.cookie":"Package_Module/path/to/jquery.cookie.min"

    },

    shim:{

        'jquery.cookie':{

            'deps':['jquery']

        }

    }};


We’ve defined a new top level configuration property named shim. This property is a javascript object of key value pairs. The key should be the name of your module (jquery.cookie above). The value is another javascript object that defines the shim configuration for this specific module.


0 comments:

Post a Comment