java - Is it a good idea to place JS, CSS and images resources in a JAR for a JSF application? -


i ask question, related another question asked times ago (without answer unfortunately :( )

imagine project divided several web-apps. have many shared resources (js, css, images). idea avoid duplications in each web-app, forced synchronize changes among web-applications.

so seems better have these resources on single place.

if have on richfaces project, resources managed jsf. example, <rich:calendar> component displays little icon. if html code image, see src attribute refers jsf link, not .png directly:

<img src="/richfaces-demo/a4j/g/3_3_3.finalorg.richfaces.renderkit.html.iconimages.calendaricon/datb/eah7cw0fw6znaa8xba4_.jsf"     style="vertical-align: middle" id="j_id354:j_id355popupbutton" class="rich-calendar-button " alt=""> 

i see following advantages of such approach:

  • include resources in classical library (i.e. in jar), eases deployment on eclipse;
  • allow generate dynamic file (i.e. css or js contain required properties);
  • allow inclusion of required resources (for ex. not load css file if not required component on page).

regarding application, need first point, important me (cf. other related question on so).

the main drawback of solution browser not able cache resources considered jsf requests. also, each of these requests have go through whole jsf lifecycle, can performance issue if number of resources in current page important...

questions

thanks.

yes, idea put shared resources in separate project included jar in main web applications. use simple @webservlet serves static resources straight classpath, along cache , gzip support. don't delegate job jsf, utilize jsf resource management in turn transparently calls servlet url.


allow generate dynamic file (i.e. css or js contain required properties)

that's doable using specific url , passing filenames of separate resources query string. static resource servlet nasty work of reading multiple resources single response.


allow inclusion of required resources (for ex. not load css file if not required component on page).

that's done @resourcedependency annotation. e.g.

@resourcedependency(library="css", name="specific.css") public class customcomponentwithcss extends uicomponentbase {     // ... } 

we use modified version of fileservlet altered resource classpath instead of local disk file system. also, range support removed (since randomaccessfile can't directly operate on classpath resources). further have added check if current stage development or not , if not, serve minified version of css/js instead put in different path.


Comments

Popular posts from this blog

c# - how to write client side events functions for the combobox items -

exception - Python, pyPdf OCR error: pyPdf.utils.PdfReadError: EOF marker not found -