Click
Click Examples

Source Viewer : WEB-INF/classes/org/apache/click/examples/page/general/PageImportsExample.java

package org.apache.click.examples.page.general;

import java.util.List;

import org.apache.click.element.CssImport;
import org.apache.click.element.Element;
import org.apache.click.element.JsImport;
import org.apache.click.examples.page.BorderPage;

/**
 * This page provides an example of how to programmatically optimize your
 * PageImports for high traffic pages. You optimize your Page by combining
 * multiple CSS and JavaScript import files into a single file, which reduces
 * the number of HTTP requests required to serve the page.
 * <p/>
 * Then you set the Page property "includeControlHeadElements" to false so that
 * Controls won't have their head elements imported.
 */
public class PageImportsExample extends BorderPage {

    private static final long serialVersionUID = 1L;

    public PageImportsExample() {
        // Indicate that Controls should not import their head elements
        setIncludeControlHeadElements(false);
    }

    /**
     * Return the list of the Page HEAD elements.
     *
     * @return the list of Page HEAD elements
     */
    @Override
    public List<Element> getHeadElements() {
        if (headElements == null) {
            headElements = super.getHeadElements();

            headElements.add(new CssImport("/assets/css/imports.css"));
            headElements.add(new JsImport("/assets/js/imports.js"));
        }
        return headElements;
    }
}