Imperva Cyber Community

 View Only
  • 1.  Image Caching Rules

    Posted 07-07-2022 09:45
    Dear Community,

    We are trying to configure custom cache rules for a website protected by Imperva Cloud WAF.

    What is the proper condition option in order to create a rule that caches only the images of that website?

    Thank you in advance.

    Best Regards,

    Kostas
    #CloudWAF(formerlyIncapsula)

    ------------------------------
    Kostas Kritikos
    Technical User
    Odyssey Cybersecurity
    ------------------------------


  • 2.  RE: Image Caching Rules
    Best Answer

    Posted 07-07-2022 10:10

    Hi Kostas,

    The default caching behavior is that we will adhere to the cache directives in the headers and cache only content that is designated as cacheable.

    If you want to cache only images, there are a couple different ways to accomplish this depending upon your site layout.

    Select the following cache mode under CDN > Cache

         Custom Caching
         Cache according to custom cache rules only

    Remember to click the Save Changes button at the top right.

    Within this same screen, scroll down and click Add Rule.

    This is where you must decide how you will identify images. As an example, if the images all reside in a directory named "images", then the filter would be:

        URL contains "^/images"

    Action: Cache Resource
    TTL: (define how long we should cache the resource)
    Rule Name: (give the rule a name)

    and click Save.

    Note: This filter will cache anything resides in a URL path that "Starts with"  "/images"


    Another example rule would be:

        URL contains ".jpg$"".jpeg$";".gif$";".png$"


    Action: Cache Resource
    TTL: (define how long we should cache the resource)
    Rule Name: (give the rule a name)

    and click Save.

    This rule will cache images no matter in which directory they reside. However, you must define all image extensions that you would like to cache. In the example above, I have defined some of the most common image types.

    Note: This filter will cache anything that "Ends with"  ".jpg .jpeg . gif .png"


    Cache Rules utilize the same filter mechanism and logic as IncapRules. I recently did a webinar over IncapRules. If you were unable to attend, I highly recommend reviewing it here: 

    Cloud WAF Masterclass - Flexing with InCap Rules *Webinar Recording*




  • 3.  RE: Image Caching Rules

    Posted 07-08-2022 03:10
    Dear Mr. Anderson,

    Many thanks for the detailed answer with the alternative scenarios, and the webinar suggestion which indeed I ve missed.

    Looking forward to applying your recommendations.

    Best Regards

    ------------------------------
    Kostas Kritikos
    Technical User
    Odyssey Cybersecurity
    ------------------------------