Skip to Main Content

Breadcrumb

Question and Answer

Connor McDonald

Thanks for the question, Greg.

Asked: March 04, 2021 - 11:40 am UTC

Last updated: March 15, 2021 - 5:05 am UTC

Version: 20.2

Viewed 1000+ times

You Asked

Hi,

Question
How can browser caching be enabled for the static files (graphics - png, jpeg - and CSS) served by an Apex website?

Attempts So Far
I have tried two things so far:
1. Enabled caching within the Apex Application, via
Application Properties --> Security --> Browser Security. Set "Cache" to Enabled .

2. Amended the .htaccess file to include
<IfModule mod_expires.c>
ExpiresActive on

ExpiresByType image/png "access plus 4 months"
ExpiresByType image/jpeg "access plus 4 months"

# CSS and JavaScript
ExpiresByType text/css "access plus 1 year"
ExpiresByType application/javascript "access plus 1 year"

</IfModule>


My Apex hosting company has confirmed that mod_expire is enabled.

Unfortunately, the static files are still not being cached (I'm using Chrome Developer tools to check this).

Chrome Developer tools also shows that the HTTP Response Headers include:
Cache-Control: no-store
[...]
Pragma: no-cache


(I'm aware that I can "cheat" and overwrite the Cache-Control value via
Application Properties --> Security --> Browser Security: HTTP Response Headers but can find no way to remove the Pragma from Response Header served.)

So...what am I doing wrong? How can Apex Browser Caching be correctly enabled?

Many thanks,

Greg





and Connor said...

Assuming you are serving the content via ORDS, then browser caching should be automatic and there shouldn't be anything needed from your side of things.

For example, here's an AskTom page - you can see all of the CSS, images etc are all cached, with length expiry times.

APEX_CACHE

If you're looking to avoid "first hit" costs per session, then you could also look at caching the resources on a webserver as well.

Peter covers this nicely here

https://www.oracle-and-apex.com/speeding-up-apex-static-application-and-workspace-files/

Rating

  (1 rating)

Is this answer out of date? If it is, please let us know via a Comment

Comments

Some more info to help other readers...

Greg, March 11, 2021 - 4:59 pm UTC

Hi Connor,

thanks for your guidance: it helped me track down the source of the problem and also deliver a solution.

It turns out that Browser Caching of Workspace images was being disabled as a result of RewriteRules in my .htaccess file (problem persisted even when everything else was removed from htaccess).

It seems that ORDS and .htaccess RewriteRules don't play nicely wrt browser caching?

The problem was solved when files were moved from the Application Workspace directly into the public_html folder.

Hope someone else finds this solution helpful.

All the best,

Greg
https://comparefootballodds.co.uk/

PS Steps 1 and 2 in the original question are still required.

Connor McDonald
March 15, 2021 - 5:05 am UTC

It seems that ORDS and .htaccess RewriteRules don't play nicely wrt browser caching?


I will ask around internally

More to Explore

APEX

Keep your APEX skills fresh by attending their regular Office Hours sessions.