Legacy Knowledge Base
Published Jul. 2, 2025

Minification May No Longer Work if JS Code Contains eval() or with() on DXP 7.0

Written By

Alfonso Crisci

How To articles are not official guidelines or officially supported documentation. They are community-contributed content and may not always reflect the latest updates to Liferay DXP. We welcome your feedback to improve How To articles!

While we make every effort to ensure this Knowledge Base is accurate, it may not always reflect the most recent updates or official guidelines.We appreciate your understanding and encourage you to reach out with any feedback or concerns.

Legacy Article

You are viewing an article from our legacy "FastTrack" publication program, made available for informational purposes. Articles in this program were published without a requirement for independent editing or verification and are provided"as is" without guarantee.

Before using any information from this article, independently verify its suitability for your situation and project.

This article serves as a reference concerning an intended change in the minification process which might break some JavaScript code.

After upgrading from Liferay Portal 6.2 to Liferay DXP 7.0, any JavaScript code that uses eval() or with() may no longer work as expected. After the minification process, variable names have been renamed, causing the data variable inside an eval expression to be undefined.

Here is an example from a view.jsp file:

<script>
var view = {

"mRender": function ( data, type, full ) {
                return eval("myFunction(data)");
}
}

function myFunction(data){
alert(data);
}

view["mRender"]("Test OK")    ;

</script>

Executing this code snippet (which works in Portal 6.2) will then throw the following error in Liferay DXP 7.0:

Uncaught ReferenceError: data is not defined
    at eval (eval at mRender ((index):1), :1:20)
    at Object.mRender ((index):13)
    at (index):13

Resolution

Workarounds Available

There are two possible workarounds you may execute.

  1. Refactor the JavaScript code to avoid using eval() or with().
  2. Set com.liferay.portal.servlet.filters.strip.StripFilter=false in the portal-ext.properties file.

Any one of these workarounds should resolve the issue.

Additional Information

See LPS-44366 for more information about switching to Google Closure Compiler to compress JS files in Liferay DXP 7.0 and Google Closure Compiler restrictions about using eval() and with().

Did this article resolve your issue ?

Legacy Knowledge Base