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.
- Refactor the JavaScript code to avoid using
eval()
orwith()
. - Set
com.liferay.portal.servlet.filters.strip.StripFilter=false
in theportal-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()
.