CodeIgniter Forums

Full Version: Enable Browser Caching in Codeigniter 3
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

after upgrading from CI 2 to CI 3 using as instruction, I'm currently having the following issue.

In CI 2 I could use the Back button of the browser to navigate to the last page. The page was fetched from Browser Cache, so text in a textarea is still there.
In CI 3, however, when pressing the Back button the page will be loaded from server.

I tried several things, but none seems to be working correctly.

- In HTML header, set meta tag with " cache-control max-age = 60 "
- Enabled webpage Caching ( This caches the page, however, new posts in my forum won't be displayed this way.
- In config.php, changed "sess_driver" from database to files and enable "pconnect" + "cache_on" in database.php
- Disabled PHP boost in my STRATO control panel.

Do you have an idea how to solve this problem?
I think I found a solution for the problem. In my header view I changed the HTML meta tag to a call to the PHP function header(). It now looks this way.

    <?php header("Cache-Control: public, max-age=60, s-maxage=60");?>

The response header now seems to get the correct values: "Cache-Control    public, max-age=60, s-maxage=60".

I think there might be some change in the CI framework code from CI 2 to CI 3. In CI 2 there was no Cache-Control entry in the response header whether the default option of CI 3 seems to be "no-store, no-cache, must-revalidate".
I had this issue happen to me recently when I migrated servers and upgraded CI. I tried your solution, but it didn't seem to behave the way my old environment behaved, so I settled on this alternate solution.

I added this to my view prior to loading the header:
<?php header_remove('Cache-Control');?>

That allowed apache httpd to resume handling the headers. I use the 'Expires' header (instead of Cache-Control) and 'Expires' was already configured in my web server.