Skip to main content

Version: 3.9.0

Serve Static Resources

Static resources are files that are served directly to clients without any modification or processing at runtime. These files are typically intended to remain unchanged and are commonly used to deliver assets such as HTML, CSS, JavaScript, images, fonts, and other media files. Unlike dynamic resources that are generated or processed dynamically on the server, static resources are pre-existing files that are served as-is to the client.

In this guide, you will learn how to configure APISIX to cache and serve static resources.

Create a Route

For demonstration, the example below will use APISIX to reverse proxy static content from the Web Hypertext Application Technology Working Group (WHATWG) public GitHub repository.

Create a route to the WHATWG GitHub repository, configure it to match the desired static resource extensions, and enable proxy-cache plugin:

curl "" -X PUT \
-d '{
"id": "static-src-route",
"uri": "/whatwg/*",
"vars": [["uri", "~~", "(.jpeg|.html)$"]],
"plugins": {
"proxy-cache": {}
"upstream": {
"type": "roundrobin",
"scheme": "https",
"pass_host": "node",
"nodes": {
"": 1

❶ Match requests looking for files with .jpeg and .html extensions.

❷ Enable proxy-cache on the route.


Send a request to the route for an HTML file:

curl -i ""

You should receive an HTTP/1.1 200 OK response and see the following file content:

<!DOCTYPE html>
<script src="/link-fixup.js" defer></script>
<title>404 Not Found</title>
body.loading div.failed, body.failed div.loading, div.failed { display: none; }
body.loading div.loading, body.failed div.failed, div.loading { display: block; }
<body onload="document.body.className = 'failed'">
<script>document.body.className = 'loading'</script>
<div class="loading">
<div class="failed">
<h1>Not Found</h1>
<p>The page you are looking for is no longer available at this URL.</p>
<p>Links to the multipage version of the specification are
unfortunately likely to break over time. You might be able to find
what you want from <a href="/multipage/">the contents page</a>.</p>
<p>If you have found a broken link on the WHATWG site itself, please
<a href="">file an issue</a>.
If you found a broken link from another site pointing to the WHATWG site,
please let that site know of the problem instead. Thanks!</p>

Similarly, you could also send a request to the route to download a JPEG image:

curl -Ov ""

You should receive an HTTP/1.1 200 OK response and see the image saved in the current directory. Logo

API Management for Modern Architectures with Edge, API Gateway, Kubernetes, and Service Mesh.


API7 Cloud

SOC2 Type IRed Herring

Copyright © APISEVEN Ltd. 2019 – 2024. Apache, Apache APISIX, APISIX, and associated open source project names are trademarks of the

Apache Software Foundation