A few years ago it was deemed state-of-the-art to store any kind of extra resources (images, css/js-files) directly on the webserver.
Of course this was just the best-practice, left with many who were not able to follow because of company restrictions: no access to web server, not allowed to store files, too many regulations, and so on.
Luckily APEX 5++ gave us nicely working Static Application Files and Static Workspace Files. Now everyone is using those to store extra files.
But there is a downside: it is still a hit on the database retrieving a BLOB.
If you think this doesn’t concern you: APEX Theme Styles and Plugin Files are loaded the same way and benefit also from a speedup.
There is a very simple way to speed things up, which also works for any ORDS webservice you might use to deliver rather static content (ie.hardly ever changing images, …).
Anyway, here we go: the solution to speed up serving dynamic content is to cache it on the webserver.
If you have read my post on the Oracle APEX Reverse Proxy Guide using nginx, you already figured I like to use nginx, a free and lightweight alternative to Apache.
At first we need to know how APEX static files work: they are served through an ORDS webservice called “r”. For example https://myhost.prost/ords/myworkspace/r/files/static/v2/testimage.png
What we can see in this file-path is the folder /r/, which in fact is a generic ORDS webservice used for all kinds of APEX files (application, workspace, theme-style, plugin, …). But there is also a version number (v2) as part of the path. Whenever we change the file (update the image, …) the version number changes.
This is great information, because it means a full file path always results in the very same file. New file, new path.
So instead of passing the same file path over and over again to ORDS to read that file from the database, we can tell the webserver to cache a copy of that file and serve it directly to the next request.
In nginx-configuration we can easily set up a cache like this:
1. configure a cache bucket2. tell nginx which file-path to cache
The explanation for all those settings is documented in the official documentation. In short: put every file found on a /ords/*/r/ subfolder for at least 24hrs and also send a 30 day expiry header to the client.
For www.builtwithapex.com we also serve images (screenshots of websites) through an ORDS webservices, which is cached in a similar manner. That helped us to speed up file access by more than 300%.
That’s what I call an easy and quick win !