jQuery in liferay 6.1.20 and 6.2

If liferay portal is rich consumer of jquery and all portlets are using it through out the application, then following is the approach that I am using in my project.

1. Create liferay hook and add jquery libraries to /html/js/jquery folder.

2. Override top_js.jspf file in your hook [It is under /html/common/themes/top_js.jspf].

Add

<script src="<%= HtmlUtil.escape(PortalUtil.getStaticResourceURL(request, themeDisplay.getCDNDynamicResourcesHost() + themeDisplay.getPathJavaScript() + "/barebone.jsp", "minifierBundleId=javascript.jquery.files", javaScriptLastModified)) %>" type="text/javascript"></script>

After

<script src="<%= HtmlUtil.escape(PortalUtil.getStaticResourceURL(request, themeDisplay.getCDNDynamicResourcesHost() + themeDisplay.getPathJavaScript() + "/barebone.jsp", "minifierBundleId=javascript.barebone.files", javaScriptLastModified)) %>" type="text/javascript"></script>

AND

Add

<script src="<%= HtmlUtil.escape(PortalUtil.getStaticResourceURL(request, themeDisplay.getCDNDynamicResourcesHost() + themeDisplay.getPathJavaScript() + "/barebone.jsp", "minifierBundleId=javascript.jquery.files", javaScriptLastModified)) %>" type="text/javascript"></script>

After

<script src="<%= HtmlUtil.escape(PortalUtil.getStaticResourceURL(request, themeDisplay.getCDNDynamicResourcesHost() + themeDisplay.getPathJavaScript() + "/everything.jsp", "minifierBundleId=javascript.everything.files", javaScriptLastModified)) %>" type="text/javascript"></script>

3. Create portal.properties file and add following properties to it.

include-and-override=portal-ext.properties

javascript.jquery.files=\
    jquery/jquery-min.js
    
javascript.bundle.ids=\
    javascript.barebone.files,\
    javascript.everything.files,\
    javascript.jquery.files
    
javascript.bundle.dir[javascript.jquery.files]=/html/js

NOTE: If you are not seeing jquery files loading then add above properties to portal-ext.properties and restart server.

Above approach is working absolutely fine in my project and I have eliminated adding script tags to portal_normal.vm under theme. Even I have overcome page load performance issue where it was loading may jquery libraries one after other where it was consuming some time in loading portlet data.

Please refer performance explanation given on each properties in portal.properties file.

0 archivos adjuntos
496906 Accesos
Promedio (2 Votos)
La valoración media es de 2.5 estrellas de 5.