Skip to main content

Posts

Showing posts with the label require

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.