Is it a good idea to host JS, CSS, and image resources in a JAR for a JSF application?

I would like to ask you a question related to another question that I asked several times ago (unanswered, unfortunately :()

Imagine that your project is divided into several web applications. You also have many common resources (JS, CSS, images). The idea is to avoid duplication in every web application, as you will be forced to synchronize your changes between all web applications.

So it’s better to have these resources in one place.

If I have a look at the Richfaces project, all of their resources are managed by JSF. For example, a component <rich:calendar>displays a small icon. If we look at the HTML code for this image, we will see that the attribute srcrefers to a link jsf, and not to .png:

<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 the following advantages of this approach:

  • Include resources in the classic library (i.e. in the JAR), which facilitates deployment to Eclipse;
  • Allow the creation of a dynamic file (i.e. CSS or JS that contain only the necessary properties);
  • Allow inclusion of only necessary resources (for example, we will not load the CSS file if it is not required by the component on the page).

As for my application, I only need the first point, but for me it is very important (see my other related SO question).

, , JSF. , JSF, , ...

.

+3
1

, , JAR -. @WebServlet , , gzip. JSF, JSF, , , URL-.


(.. CSS JS, )

URL-, . .


(, CSS, ).

@ResourceDependency . .

@ResourceDependency(library="css", name="specific.css")
public class CustomComponentWithCSS extends UIComponentBase {
    // ...
}

FileServlet, , . , ( RandomAccessFile ). , , , , CSS/JS, .

+1

All Articles