ADF12cR2: Boost Page Image Rendering with Lazy Loading

In Oracle WebCenter Portal or Oracle ADF Applications is very common the usage of some Image Galleries or other kind of web content pages with Images or Videos in high resolution.

In Oracle ADF can be applied the same techniques used in the common Web Sites developed by using JavaScript technologies.

This example shows how to use one of the many Image Lazy Load implementation you can find in Internet nowadays. In this case I will make use of https://github.com/verlok/lazyload

https://github.com/DanielMerchan/adf

How to use the basics of this library?.

It is required to import the lazyload.js javascript library, populate the data-src HTML attribute in the img tag  as explained in the LazyLoad GitHub.

But, how can I add the data-src attribute in an ADF Image tag?.
The ADF Operator Tag <af:passThroughAttribute> can be used with any ADF tag for rendering custom HTML attributes which are not in the out-of-the-box Catalog.

<af:document title="untitled1.jsf" id="d1">
        <af:form id="f1">
            <af:image id="i1" styleClass="lazyload"
                      source="/images/giphy.gif">
                <af:passThroughAttribute name="data-src"
                                         value="https://images.pexels.com/photos/145939/pexels-photo-145939.jpeg?auto=compress&amp;cs=tinysrgb&amp;h=750&amp;w=1260"/>
            </af:image>
            <af:image id="i2"  styleClass="lazyload"
                      source="/images/giphy.gif">
                <af:passThroughAttribute name="data-src"
                                         value="https://images.pexels.com/photos/378570/pexels-photo-378570.jpeg?auto=compress&amp;amp;cs=tinysrgb&amp;amp;h=750&amp;amp;w=1260"/>
            </af:image>
            <af:image source="/images/giphy.gif" styleClass="lazyload"
                      id="i3">
                <af:passThroughAttribute name="data-src"
                                         value="https://images.pexels.com/photos/672532/pexels-photo-672532.jpeg?auto=compress&amp;cs=tinysrgb&amp;h=750&amp;w=1260"/>
            </af:image>
            <af:image source="/images/giphy.gif"  styleClass="lazyload"
                      id="i4">
                <af:passThroughAttribute value="https://images.pexels.com/photos/38278/tiger-head-wildlife-animal-38278.jpeg?auto=compress&amp;cs=tinysrgb&amp;h=750&amp;w=1260"
                                         name="data-src"/>
            </af:image>
        </af:form>
        <af:resource source="/js/lazysizes.min.js" type="javascript"/>
    </af:document>
In this example, a loading gif is shown while the page renders and the images are loaded after the page has been rendered.



Then, the images are loaded after the Page has been loaded.


You can use a low-res version of the image in the first rendering and the replace it by a hi-res image.

More information and the project in my ADF Samples in GitHub

Comments

Popular posts from this blog

OJET: Inter-Module communication in TypeScript Template

OJET: Build and Deploy in an Application Server

OJET: Select All options using only Checkboxset