Cache browser images if no file extension provided - caching

When a browser requests a jpg and the server returns the data but not as a reference to a jpg file but rather sends the jpg data itself, is it possible for the browser to cache the data?
For example:
http://www.somewebsite.com/image/abc
This uri returns jpg data. Is there some way to get the browser to cache the data it receives to avoid having to request it again?

I just attempted to debug your example but received an Account Suspended. Webmaster, please, contact support. page!
So as I am working blind can I suggest researching the header('Expires: SOME DATA HERE') function in PHP (I assume you are using PHP).
If the solution does not lie there you can also use .htaccess to set the headers using
<IfModule mod_expires.c>
ExpiresActive On
############################################
## Add default Expires header
## http://developer.yahoo.com/performance/rules.html#expires
<FilesMatch "\.(ico|pdf|flv|jpg|jpeg|png|gif|js|css|swf)$">
ExpiresDefault "access plus 1 year"
</FilesMatch>
</IfModule>
This example taken from http://www.robertwent.com/blog/servers-and-hosting/45-set-expires-headers-in-htaccess
Ultimately it is the headers that tell the browser how you advise the content is cached. What the browsers actually does can sometimes be surprising.

Related

ckeditor uploading images

So I have my ckeditor working nicely together with the uploader of the fckeditor.
But only on localhost.
When uploaded to my server, the file manager uploads the Photo to the designated folder, but doesn't seem to get the url back for implementing it in the editor. I then always get the error of "image source url is missing".
Can anyone tell me what I am missing here ?
How come it works on localhost and doesn't on the server ?
I do think I changed all the appropriate paths.
Cheers
Chris
I found the solution of this error in CKEditor when you upload image file. This problem is due CKEDITOR open dialog in a frame so ; for solving this error check the "X-FRAME-OPTION" in you htaccess and set the value to SAMEORIGIN instead of DENY. If it's not in your htaccess it's when you send http header in your app.
For PHP before send content just set header like this :
header('X-FRAME-OPTION : SAMEORIGIN');
For more information about X-FRAME-OPTION check this link https://developer.mozilla.org/en-US/docs/Web/HTTP/X-Frame-Options.
Best regards
in my case (in .htaccess) it was obligatory to unset the header value first which was added by (I suppose) server:
<ifModule mod_headers.c>
Header unset X-Frame-Options
Header set X-Frame-Options SAMEORIGIN
</ifModule>

Not receiving X_REQUESTED_WITH request header in Apache localhost

I just set up Apache 2.4 32-bit on my Windows 7 desktop and I am testing a simple AJAX website. I have an .htaccess file that directs all non-resource-file requests to index.php, and within this .php script I check $_SERVER["HTTP_X_REQUESTED_WITH"] to determine if a given request is ajax or not (I set this header myself when I send the ajax request).
Though the header is getting set, Apache seems to be dropping it before my .php script runs. I can see the request header in Chrome, but it's not there in the .php script. I even tried logging \"%{X_REQUESTED_WITH}i\" in Apache's access.log, but I don't see it there either.
This functionality works when the site is running on Bluehost. Do I need to configure Apache to get it to work on my local machine?
Apache 2.4 now drops all headers with underscores, for 'security' reasons.
According to their docs, you can add them by adding this to your htaccess:
SetEnvIfNoCase ^Accept.Encoding$ ^(.*)$ fix_accept_encoding=$1
RequestHeader set Accept-Encoding %{fix_accept_encoding}e env=fix_accept_encoding
Where Accept.Encoding and Accept-Encoding is the header name. Underscores are replaced with dots and hyphens respectively.

Add expire header to improve the performance of page using .htaccess

I have a great .htaccess code which really improve my page speed.
This one below I below I don't really know much but from looking at it is like to compress or something not really sure
<FilesMatch ".(js|css|html|htm|php|xml)$">
SetOutputFilter DEFLATE
</FilesMatch>
This one is really great which set the Expire header for everything to 10 years and text/html to one day
ExpiresActive On
ExpiresDefault "access plus 10 years"
ExpiresByType text/html "access plus 1 day"
So This one is use to unset ETag which is one of the requirement rules of YSlow
Header unset ETag
FileETag None
Now come to my question that I have problem with.
I can't really use w3 Total cache with my Wordpress blog because it gives me some random issue like only show one ramdom old post to my home page and to solve that is to delete the cache and then after a day it will happen again.
So I can't rely on that plugin, but with my 3 codes that I added in my .htaccess is really good with one exception and I don't know really how to fix that.
say for example I visit my site http://applesiam.com this morning and during the day I have 3 new posts. If I don't really do hard reload page I will still see the one from morning.
So this is really make me confuse.
What should I change to not to cache the actual home page so it will be updated except images and the rest.
I'm not sure if this is going to work but I found this which is going to solve the behaviour of the browser cache the file that update dynamically
# Force no caching for dynamic files
<filesMatch "\.(php|cgi|pl|htm)$">
ExpiresActive Off
Header set Cache-Control "private, no-cache, no-store, proxy-revalidate, no-transform"
Header set Pragma "no-cache"
</filesMatch>

URL Rewritten and Cache control apache htaccess

I have a page index.php which depending on the arguments provided generates different output.
Using mod_rewrite i have those files a a.htm, b.htm and c.htm .
Now, i want these particular 4 Files (or URLs actually) to be cached locally,
for that i have tried
<FilesMatch "(a\.htm|b\.htm|c\.htm)$">
FileETag None
Header set Cache-Control "max-age=7200, public, must-revalidate"
</FilesMatch>
But it doesn't work.
how do we go about this issue ?
RewriteEngine on
RewriteRule index.htm index.php
<FilesMatch "index.htm">
FileETag None
Header set Cache-Control "max-age=7200, public, must-revalidate"
</FilesMatch>
This is a sneak peak of what i have right now. But in the long run there will be lots of files and rewritten url's. so i want to add cache headers via htaccess . hope it makes sense !

Apache Reverse Caching Proxy - why isn't it caching?

I am attempting to set up a reverse caching proxy for ad graphics (GIF, JPEG, SWF) serving. The proxying is working fine and sending the request on to the origin server, but I can’t seem to figure out why the content isn't being cached. My current config is below. The goal is to cache all requests that match the /ca/ URI prefix. The origin server is serving the files with clean URLs, no file extensions, Cache-control max-age=1 week set on the origin server headers.
ProxyRequests Off
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
<IfModule mod_disk_cache.c>
CacheEnable disk /
CacheRoot "/var/cache/mod_proxy"
CacheDirLevels 3
CacheDirLength 5
CacheIgnoreCacheControl On
</IfModule>
RewriteCond %{REQUEST_URI} ^/ca/*
RewriteRule ^/(.*)$ http://origin.webserver.com/$1 [P,L]
Currently, the only caching I’ve seen actually happen is that of local files accessed on the proxy servers, I’m looking for what I’m missing to get content fetched from the origin server to be cached.
I’m wondering if it has to do with mod_cache not caching because the content is fetched from the origin server, and not on a location on disk.
I am looking for a way to force all requests matching that prefix to be cached.
P.S. It looks like I’m having this exact issue: http://mail-archives.apache.org/mod_mbox/httpd-users/200901.mbox/%3C497F6ED3.7080606#gmail.com%3E. I will be checking my permissions and go over debug messages…
Adding these directives seemed to kick the cache mechanism into gear. I figure it has to do with expiration and cache-control headers as sent from the origin server since I'm serving up images with Symfony/PHP5 instead of directly from the filesystem.
<IfModule mod_disk_cache.c>
CacheEnable disk /
CacheRoot "/var/cache/mod_proxy"
CacheDirLevels 3
CacheDirLength 5
CacheIgnoreCacheControl On
CacheMaxFileSize 100000000
CacheIgnoreNoLastMod On
CacheMaxExpire 1209600
CacheIgnoreQueryString On
</IfModule>

Resources