assets jquery minify System Administrator Jahia 7.3 Legacy

Exclude js from minification

Question

When using javascript included in a JSP page with the template:addResources tag (<template:addResources type="javascript" resources="myjs-3.3.1.js"/>) it causes an exception to be thrown : 

com.yahoo.platform.yui.org.mozilla.javascript.EvaluatorException: Compilation produced 71 syntax errors.

YUI compressor contains bugs that thus propagates to Jahia. 

 

Answer

There is a way to exclude one or more resources from minification: In template:addResources add a parameterkey

<template:addResources type="javascript" resources="libraries/jquery-3.3.1.min.js" key="jquerymin"/>

In applicationcontext-renderer.xml we have an attribute excludesFromAggregateAndCompress where you can specify scripts and CSS which shouldn't be aggregated:

The applicationcontext-renderer.xml can be found in webapps/ROOT/WEB-INF/lib/jahia-impl-*.jar\org\jahia\defaults\config\spring

<bean id="staticAssetsFilter" class="org.jahia.services.render.filter.StaticAssetsFilter">
    <property name="priority" value="0"/>
    <property name="description"
              value="Render filter that 'injects' the static assets into the HEAD section of the rendered HTML document."/>
    <property name="applyOnConfigurations" value="page,gwt"/>
    <property name="applyOnTemplateTypes" value="html,edit,html-.*"/>
    <property name="scriptEngineUtils" ref="scriptEngineUtils"/>
    <property name="ajaxTemplate" value="/WEB-INF/scripts/ajaxResources.groovy"/>
    <property name="template" value="/WEB-INF/scripts/resources.groovy"/>
    <property name="aggregateAndCompress" value="${aggregateAndCompressAssets:true}"/>
    <property name="excludesFromAggregateAndCompress" ref="excludesFromAggregateAndCompress"/>
    <property name="forceLiveIEcompatiblity" value="${forceLiveIEcompatiblity:false}"/>
    <property name="ieHeaderRecognitions">
        <set>
            <value>msie</value>
            <value>trident/7</value>
        </set>
    </property>
    <property name="addLastModifiedDate" value="${addLastModifiedDateInAssets:false}"/>
    <property name="aggregateSupportedMedias"
              value="${aggregateSupportedMedias:screen,handled,print,aural,speech,braille,embossed,projection,tty,tv,all}"/>
</bean>

<util:list id="excludesFromAggregateAndCompress">
    <value>jquerymin</value>
</util:list>

You can extract this bean and past it in the /digital-factory-config/jahia/applicationcontext-custom.xml where you can overload the beans.
Please note this modification need to be maintained during Jahia upgrades process (manual action have to be taken in this case like verifying if the bean definition has not evolved).