Enable Browser Caching in Codeigniter 3 - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5) +--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24) +--- Thread: Enable Browser Caching in Codeigniter 3 (/showthread.php?tid=65998) |
Enable Browser Caching in Codeigniter 3 - StevePINA - 08-21-2016 Hello, after upgrading from CI 2 to CI 3 using http://www.codeigniter.com/userguide3/installation/upgrade_300.html 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 (https://www.codeigniter.com/userguide3/general/caching.html). 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? [SOLVED] Enable Browser Caching in Codeigniter 3 - StevePINA - 08-23-2016 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. Code: <head> 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". RE: Enable Browser Caching in Codeigniter 3 - cisspGuy - 10-22-2019 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. |