Jump to content
We've recently updated our Privacy Statement, available here ×

JasperServer 5.6: how to "regenerate" optimized js files


mouadineyo
Go to solution Solved by elizam,

Recommended Posts

Since 5.6, JasperSoft uses the require.js library to optimize javascript performance, by merging and compressing js files.

In previous versions of JasperSoft, I used  to change some js files, and those changes were considred.  But since 5.6 and the JS optimization, I didnt manage to make those changes effective as the js files I used to edit are not used anymore by JasperSoft. I tried to directly edit the files in the "optimized-script" directyory but once again those files are not used.

By digging around with firebug i managed to understand that there is some "merged and compressed" js files used. Those files don't take my changes in the originals JS files in consideration alought I clear cache. If I edit them directly, it works.

But according the situation, different "merged and compressed" js file are used (sometimes "optimized-script/home/homePage.js, sometimes results.js, ...) , and it is quite difficult to edit all of them, especially when those are are minimized / compressed file.

The new javascript optimizer mecanism is quite difficult to understand, and i didn't see anything about it in the docs.

I'm looking for a way to "recompile" the javascript files from the original sources (those in the /scripts directory) with require.js.

I tried to install node.js and require.js on my debian distribution, and to "recompile" using the "build.js" file in the script directory. But i'm getting some errors. The config file used is quite complicated ...

I guess JasperSoft Server probably have an embeded node.js, and I hope there is a way to regenerate the optimized js files from the original sources.

Did someone find a way, or have an idea of how to do this ?

Best regards.

Link to comment
Share on other sites

  • Replies 6
  • Created
  • Last Reply

Top Posters In This Topic

  • Solution

I'm working on documenting that right now! 

1. Create a working directory where you can copy JavaScript files and install and run the required scripts. In
this example, the directory is called Working.
2. Create a subdirectory for a copy of the JavaScript files from JasperReports Server. This directory is called jssources.
3. Copy the following directories from the JasperReports Server directory, <js-webapp>, to js-sources:
• Copy <js-webapp>/scripts to js-sources/scripts.
• Copy <js-webapp>/fusion to js-sources/fusion
4. Back up your js-sources directory.
5. Create a js-optimization-output directory for the output of the optimization process.
6. Download and install node.js from http://nodejs.org/. Place the nodejs folder directly in your Working
folder.
7. Download r.js, a requirejs optimization file, from http://requirejs.org and place it directly in the Working
folder.
8. Make your changes to the JavaScript files in Working/js-sources.
9. Open a command line tool and run the commands to optimize the JavaScript. The following example is for
Windows, it places the output in the Working/js-optimization-output folder:
% cd Working
% nodejsnode r.js -o js-sourcesscriptsbuild.js appDir=js-sourcesscripts baseUrl=. optimize=uglify2 dir=js-optimization-output

10. Copy the optimized scripts from js-optimization-output to <webapp>/optimized-scripts (where webapp is the location of your JRS)
11. Reload the web app in the app server to see the changes.

This will be in the next revision of the Ultimate Guide.

Link to comment
Share on other sites

Thanks you for your responsiveness, this is exactly what I was looking for !

Nonetheless, the whole rebuild process is quite long, making incremental testing of small modifications tedious ... The smalles possible modification (for example just quoting a line in a JS file) requires 20 minutes to be tested (10 min rebuild + 10 min to upload the whole directory as we don't know wich files have been updated).

Is there a way to only rebuild the necessary files (those impacted by a modification) ?

Link to comment
Share on other sites

It looks like there is, but you have to set it up at build time. If you are doing this on a test or staging server, you might just want to temporarily disable optimization optimization by setting javascript.optimize=false in the /WEB-INF/js.config.properties file and then reloading or restarting the server. You only have to do this once. You can temporarily disable optimization, try out your changes, and then enable optimization and copy and optimize your final files as described above.
Link to comment
Share on other sites

  • 4 months later...

I might be late in the game here, but I just had the same issue and found out that if your change is relatively small, instead of re-building whole optimized folder you can simly modify individual file. Look for the build.txt file in optimized-scripts folder. There you can see how individual scripts are groupped together into few large optimized files. Find out which file your original script went to, open it with text editor and modify. Note that optmized files have all whitespaces and linebreaks removed, so it is not super easy to locate code in question and modify it, but, for small changes it is still much easier than re-builiding the whole thing.

Link to comment
Share on other sites

  • 1 year later...
I followed steps above to regenerate optimized-scripts folder(changed Authentication.js file) and I can see that minified version contains my changes. However it seems that it never execute on browser, like it did not updated files. I did not reload web app with tomcat7 manager-ui(could not configure it to work on AWS), just restarted tomcat7. Could that be problem? AWS JasperServer version is 6.1 NOTE: when I turn off optimization, my code fix is working.
Link to comment
Share on other sites

  • 2 years later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...