HTTP Function Changes Doesn't Take Affect (Cache Control)

While I’m building something with HTTP-Endpoint I solved a problem that someone can spent their hours to solve it if they are not familiar with it (like me).

If you are having a problem with your API (HTTP-Endpoint):

  • Your code changes not taking any affect.

  • You are getting same response even if you change the code.

  • Or similar responses.

Your problem may cause because of one missing header option: “Cache-Control”: “no-cache”

I was trying to build a file download system using AWS with my Wix site but my changes were not affecting to my API so I remembered that maybe it’s caching the request and I was right it was caching the request.

There are some request types that will be cached:

  • 200 (OK)

  • 301 (Moved Permanently)

  • 404 (Not Found)

  • 206 (Partial Content)

What you should do to let browser not cache your request?

You need to add a header option to your response and you need to clear your browser caches (cookies) to see changes.

Example response: (using response HTTP API)

return response({
            status: 301,
            headers: {
                location: 'https://www.example.com/'
                'Cache-Control': 'no-cache'
            }
        })

If you add this ‘Cache-Control’: ‘no-cache’ to your headers in your response browser will not cache your request again.

Tip: Use Postman to check your API responses. (It’s free)

More about caching requests.
More about Cache-Control

If I wrote something wrong let me know :slight_smile: