Welcome Guest, Not a member yet? Register   Sign In
How do I cache my images? I put $this->output->cache(100) but it is not working
#1

[eluser]Unknown[/eluser]
Hi, I ran the Google Page Speed and found that my images are not cached. It suggests me to add an expire headers.. How can I add this? Isn't adding the $this->output->cache enough for caching?

And I noticed that my .htaccess doesn't work.. My website have 20+ images. So I want to add expire headers to them all but I don't know how.. I'm new in PHP and Apache, I don't have any idea how to add expire headers.. I just jumped in right away to Code Igniter.. Please teach me how to add cache.
#2

[eluser]Unknown[/eluser]
What Google Page Speed is telling you is, that you require expire headers, which are used by the browser to identify for how long it should keep the files in its cache without checking if they had changed.

Okay, so.
If you manage to somehow get access to your .htaccess file, you may set the following rule:
Code:
<FilesMatch "\.(ico|jpg|jpeg|png|gif)$">
Header set Cache-Control "max-age={NUM_SECONDS}, public"
</FilesMatch>
Where {NUM_SECONDS} is equal to how long images should stay in browsers cache after the first visit. (in seconds), lets say: "3600" for 1 hour after first time view.

If however, you don't have access to the htaccess file, php needs to stream out the files and add headers to them. But if you are just starting with PHP, then maybe rather try working out why .htaccess doesn't work.




Theme © iAndrew 2016 - Forum software by © MyBB