Liferay : Overwrite Cache-Control headers in Document Library files

No comments

DLFileEntry from Document library are downloaded from WebServerServlet, that is adding Cache-Control: private header but no other caching instruction (like max-age or Expires) is appended.

ServletResponseUtil will override the Cache-Control header, no matter what was set before. In this particular case, when trying to modify the header using the HeaderFilter will fail because the portal will override it with a hard-coded value later on.

Overwrite Cache-Control headers settings.

  1. Shut down the portal.
  2. Edit the <tomcat_home>/webapps/ROOT/WEB-INF/liferay-web.xml
  3. Add the following filter mapping:

      <filter-mapping>
        <filter-name>Header Filter</filter-name>
        <url-pattern>/documents/*</url-pattern>
       </filter-mapping>
    I’ve added it after the following block:

   <filter-mapping>
        <filter-name>Header Filter</filter-name>
        <url-pattern>*.png</url-pattern>
    </filter-mapping>

Start the portal again.

Check Header detail in the brwoser.

Before configuration change

Open the browser with cache cleaned. Also open network tool using (F12).
Try open the URL which has document library file.

URL: https://localhost:8080/documents/20197/983069/bim-fp.jpg/8177e209-45b9-43b1-8311-9cc5230e8973?t=1463000778069
Result:  This should have “Cache-Control: private”

After configuration change

Open the browser with cache cleaned. Also open network tool using (F12).
Try open the URL which has document library file.

URL: https://localhost:8080/documents/20197/983069/bim-fp.jpg/8177e209-45b9-43b1-8311-9cc5230e8973?t=1463000778069
Result: This should have “Cache-Control:max-age=315360000, public”

                                                                                                                                     

V3A InfoLiferay : Overwrite Cache-Control headers in Document Library files

Related Posts

Leave a Reply

Your email address will not be published. Required fields are marked *