Reduce JSF Session Size

The development of web applications requires the developer to store states. You may save them on the client, on the backend or also in a database. Using JSF, the web session preserves the state of the CDI or container managed beans on the backend. A common approach is to save the state not in the session scope(@SessionScope) but in the view scope(@ViewScope). So after leaving the view the object representing the states are free for garbage collection and there is no need for the JavaEE server to wait with the recycling for the session to expire. Inspecting your session with XRebel or any other tool you may notice, that also if you view scoped all your objects the session may increase after each view change because the view scoped beans are kept in session memory for quite some time. That is, at least in Mojarra, a feature because the ViewScopeManager holds all view scoped beans for the last 25 views by default. You can change the behaviour with a context parameter in your web.xml. The parameter is called com.sun.faces.numberOfLogicalViews.
In JSF < 2.3 there is a bug in Mojarra so the context parameter is ignored. The solution is to use OmniFaces @ViewScopedor you may set the parameter in your application with a SessionListener.

public class SetActiveViewMapsSizeSessionListener implements HttpSessionListener {  
    public void sessionCreated(HttpSessionEvent event) {
        event.getSession().setAttribute(ViewScopeManager.ACTIVE_VIEW_MAPS_SIZE, 1);