Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you minify/obfuscate JavaScript code in a JSP that has JSP/JSTL variables mixed into it?

arrays.jsp:

//...
var x = <c:out value="${x}"/>
<c:if test="${empty doExternal}">
processExternalArrays();
</c:if>
//...

I want to minify/obfuscate JavaScript contained in a large JSP file in which numerous JSP/JSTL variables are mixed into the JavaScript code such as in the snippet above.

The code relies on variables populated using server-side logic and then passed to the client-side code, as above.

I'm already minifying my JS files using YUI compressor but I don't know what to do about the JavaScript code in my JSPs.

Is it possible to minify/obfuscate this code, given that it is dynamically created?

like image 608
Oscar Reynes Avatar asked Nov 22 '10 18:11

Oscar Reynes


1 Answers

Probably the best solution for you would be use Granule JSP tag. You can download it at http://code.google.com/p/granule/

code sample is:

<g:compress>
  <script type="text/javascript" src="common.js"/>
  <script type="text/javascript" src="closure/goog/base.js"/>
  <script>
       goog.require('goog.dom');
       goog.require('goog.date');
       goog.require('goog.ui.DatePicker');
  </script>
  <script type="text/javascript">
      var dp = new goog.ui.DatePicker();
      dp.render(document.getElementById('datepicker'));
  </script>
</g:compress>
...
like image 96
Andre Avatar answered Sep 24 '22 03:09

Andre