I was recommended that I move this question from StackOverflow to here.
I am running a web site on a server with Tomcat and IIS. I use .JSP and Java in the back end.
I don't know how to configure IIS to automatically minify resource files (CSS, JavaScript, images) when using .JSP. I have found a few suggested solutions online, but they all apply to IIS and .ASP.
I added the "compression" tag to this post because there is no "minification" tag available, but I am not referring to gzip compression, but removing white spaces, merging resources for faster download etc.
Could anyone help me figure out how to configure IIS to minify resource files with .JSP? Thank you!
Minification a process which combines multiple CSS or JS files to a single file and perform process of compression(whitespace removal) and obfuscation(JS) is an ideal build time solution, rather than a run time solution. While using Tomcat with IIS, it will be good to have some thing like this:
Use WRO4J as a maven build time plugin. Create an attribute like
devmode=true or false. In JSP's have if else condition to define
groups to add multiple CSS/JS or Single based on the devmode value.
While deploying use devmode = false. This with maven configuration will compile JSP with single CSS/JS files.
In IIS, configure a separate VD and map your static resources of war to it. Write a rewrite rule to instruct IIS to serve the static resources. Enable static compression.
The above said configuration will take less load on the CPU.
Some links of interest could be:
https://code.google.com/p/wro4j/wiki/MavenPlugin
Unobtrusive way to combine and compress javascript/css for java/spring/maven applications?
Related
I am currently working in a WEB Java project and I have the following requirement: I have to make sure our customers don't have access to the packaged files in order to change them. Actually, I'd like to do that with only a few of those classes but without using any obfuscators due to the size of my project and the resources it uses to accomplish some tasks (reflection, annotations, interceptors, etc).
Does anybody have any tips?
Thanks,
Luan
We are using CDN for our custom theme. Now we want to do same for all Liferay static resources(js,images,css and fonts). Has anyone done this before? We are planning to move whole /html of ROOT to CDN. But we faced some issues regarding compass from some css files which imports compass. What is the ideal scenario while uploading Liferay's static resources to CDN? Any help? We are using cdn.host.http in portal-ext.properties.
Do not move resources from the webapp to the CDN! A lot of those things are not actual resources, but more of a ‘source’! For example, the css in the ROOT/html are actually SASS files and will not work if moved as is. The best solution is to use a Squid-like proxy to cache resources from the actual tomcat portal as they are requested.
In a large web application, I'm using requirejs amd modules so that the scripts themselves are modular and maintainable. I have the following directory structure
web
|-src
|-main
|-java
|-resources
|-webapp
|-static
|-scripts
|-styles
|-images
|-static-built //output from r.js. not checked into git
|-WEB-INF
During build js and css are optimized using r.js into static-built folder. Gradle is the build tool.
Now the problem: The jsps refer to the scripts in static/scripts folder and this is how i want when working locally. However when building war, I want the static files to be served from static-built folder. The important thing is the source jsp should not have to change to serve the optimized files from static-built folder.
Two options that I have are: a) the gradle build while making war should include static-built instead of static. b)include static-built in addition to static and using tuckey urlrewrite pick the resouce from static-built rather than static.
What best practices are the community following in similar scenarios?
We've setup the server to have a runtime profile (dev, qa, prod, etc) read from a system property which determines some settings based on it. When running in production profile we serve the optimized files from the WAR. In development we serve the non-minified and non-concatenated files directly from the filesystem outside the application context.
Files are structured according to the official multipage example.
Configuring serving files depends on your chosen backend solution. Here's an example for spring.
Alternatively, r.js can generate source maps and those will help with development as well.
Not sure if this question is outdated already, but I had a kind of similar problem.
I had similar project structure, but with the only difference - I've split the project into 2 modules:
one of them (let's call it service) was java-module for back-end
the second one contained only js and other stuff related to front-end (let's call it ui).
Then in Gradle build 'assemble' task of the service depends on 'assemble' task of ui AND another custom task called 'pre-assemble'. This 'pre-assemble' task was copying the optimized js files to place where I wanted them to be.
So, basically, I've just added another task that was responsible for placing all the optimized js files in the proper place.
I see a barebone.jsp file created (I guess by the MinifierFilter) as well as for deploying compressed and cached js. I want to separate development and production cases, and as for development, I just don't want Liferay not only to cache produced javascript file, I don't want to have this generated instance at all.
To be more precise, I want all javascript files to be concatenated on the fly. I always want to have an opportunity to edit any statics files at development and to see results as soon as possible.
What is the easiest way to implement it?
include the settings from portal-developer.properties in your portal-ext.properties. This disables minifiers, caching etc. and you can develop without the problems mentioned. You don't want this setting in production though, as all files will be loaded individually.
(Edit: It might be advisable to include my comment from below in the answer):
You find this file in webapps/ROOT/WEB-INF/classes
All the *.fast.load parameters are for the various minifiers (css, js), but typically you want all of the parameters named in there.
I want to know what is .do extension in web pages. Is it a standard extension, or, if it's not, can we change the extension (like client-login.php to client-login.do and still run as PHP)?
Thanks.
.do comes from the Struts framework. See this question:
Why do Java webapps use .do extension? Where did it come from?
Also you can change what your urls look like using mod_rewrite (on Apache).
".do" is the "standard" extension mapped to for Struts Java platform. See http://struts.apache.org/ .
It is whatever it is configured to be on that particular web server. A web server could be configured to run .pl files with the php module and .aspx files with perl, although that would be silly. There are no scripts involved with most web servers, instead you'd have to look in your apache configuration files (or equivalent, if using different server software). If you have permission to edit the server config file, then you could make files ending in .do run as php, if that's what you're after.
Using apache's rewrite_module can change your script extensions. Give this thread a good read.