Add jQuery in portlet level:
Suppose we have injected jQuery in 2 different portlets as shown in the above and both the portlets are added on the same portal page. In this scenario the jQuery will be loaded 2 times which may cause some conflicts.
Making jQuery available for all portlets:
Sometimes we may require jQuery for multiple portlets. In that case adding jQuery in individual portlet does not make any sense. So we must make jQuery available for the entire portal. There are 2 options we can make jQuery available for the entire portal.
Option 1: Including jQuery in theme level
The file portal_normal.vm of a theme is loaded on each page of the portal. Therefore this file is the good choice to add our jQuery stuffs. Including jQuery in portal_normal.vm will make jQuery available for all the portlets. Just to add below lines in header section of portal_normal.vm file.
Here we are adding jQuery from external source. If required we can download the JS file and keep it under js folder of the theme. After that we can point to the local jQuery file of the theme.
There is a problem in the above approach. If we change the theme then our jQuery will no longer be available. The above approach is applicable when we know that our theme is not going to change in future and we are stick to one and only one theme.
Option 2: Inject jQuery by Hook
The cookie settings on this website are set to "allow cookies" to give you the best browsing experience possible. If you continue to use this website without changing your cookie settings or you click "Accept" below then you are consenting to this.