Skip to main content

What is the right way of adding jquery to the page?

What is the right way of adding jquery to the page?
There is no "right" way. All depends on what you want to achieve or avoid. For example, SFRA exposes jQuery at the very beginning of JS execution like:
window.jQuery = window.$ = require('jquery');
In that way, you have access to $ in any code you execute below without adding additional bundling mechanisms.
The drawback is that you "ban" jQuery and $ names globally for yourself and should always remember it, especially when you use 3-rd party scripts, just controlling (while you can't do it fully) what they can do with this names. Also, there is no way to understand, if jQuery is used on a particular page or not, it always here, even when the page does not need it.

Comments

Popular posts from this blog

Variation Group in SFCC

Variation Group in SFCC Technically a variant could be in multiple groups. One way to do this is to get the ProductVariationModel of that variant's master. Then you could set the selected value (setSelectedAttributeValue(String, String)) of the attribute your group is represented by. Finally you can get the collection of groups (getVariationGroups()) that share that selected value. Demandware Docs

Response Structure coming from OCAPI

Is there anyway to change the response structure coming from OCAPI? There are hooks for certain OCAPI endpoints that you can use to modify the output.If need something more specific and it goes with use case ... create a custom controller to get what you need in a certain format.

How to create dynamic urls without actually having sub-categories ?

How to create dynamic urls without actually having sub-categories ? By using only root categories, without sub categories and use search refinements to get desired results page. We can use dw.web.URLUtils class to create links from code. Use $url$ content link function to create links from content. Use Search-Show as controller route, add prefnX and prefvX parameters to apply the needed refinements where X is a number starting from 1