What is the best method to GZIP a JSF-Seam web app pages

前端 未结 8 1711
眼角桃花
眼角桃花 2020-12-06 03:33

I\'m developing an JSF web app on Tomcat, planning to use Seam in the near future, and I want to add compression of our web pages and resources (i.e. Javascript & CSS fi

8条回答
  •  佛祖请我去吃肉
    2020-12-06 04:28

    GZIP filter will reduce the initial load time significantly.
    You can additionally implement a cacheFilter to bring performance of your screens at par with JavaScript based UI (https://stackoverflow.com/a/35567540/5076414).
    For client side components, you can use Primefaces which is JQuery based UI.

    Enable GZIP filter in JSF

    Simply add this to your

    web.xml

    
        gzipResponseFilter
        org.omnifaces.filter.GzipResponseFilter
        
            The threshold size in bytes. Must be a number between 0 and 9999. Defaults to 150.
            threshold
            150
        
        
            The mimetypes which needs to be compressed. Must be a commaseparated string. Defaults to the below values.
            mimetypes
            
         text/plain, text/html, text/xml, text/css, text/javascript, text/csv, text/rtf,
         application/xml, application/xhtml+xml, application/x-javascript, application/javascript, application/json,
         image/svg+xml, image/gif, application/x-font-woff, application/font-woff2, image/png
     
        
    
    
        gzipResponseFilter
        /*
        REQUEST
        ERROR
    
    
        java.lang.Throwable
        /
       
    

    And the following to your

    pom.xml

        
            org.omnifaces
            omnifaces
            1.11
        
    

    How to verify if my screen is using gzip

    To see if your contents are already usign gzip and cache, In your Google Chrome Browser -> right click on your screen -> inspect -> click network tab -> refresh your screen. Click on the images, icons, stylesheets and see if you see following in response header

    Content-Encoding:gzip if the status of element is 200

提交回复
热议问题