Best Practices - Common js,img,css files shared by multiple projects

One day, I was just reading developerworks forum queries and response.
Usually I love to read and reply more and more portal quires posted on forums.

During that time, I just came across to a query where, somebody asked about "where to keep common js,css,img files  and refer them into your multiple portlet projects"
I replied there and also thought about sharing on my blog.

Following are the best practices to keep all your common js,img,css files shared by multiple portlets project

For your dev,stag,prod environments :-

The best place would be to put all these static files(js,img,css) on your Web Server and just refer them  from your jsp files.
Example:- If you have copied js,img,css folders to staticFiles on WebServer then refere them in your jsp as below

<script src="/staticFiles/js/test.js" type="text/javascript"

same applies for css and img.

For your localhost portal:-

Since there will be no WebServer on local environment, you can do following steps to achieve the same.

Create a Web Project. 

Put all your js,css,img files to web content folder.
Export this project as EAR and 

Install this EAR through WAS console and 
Provide application context root as /staticFiles.
Click Finish and Save.

Now, in your portlet jsp files, refer your js,img or css files like

<script src="/staticFiles/js/test.js" type="text/javascript"></script>

Same applies for css and img.

No comments: