I'm trying to serve static content from a cookieless domain. I've created a separate domain altogether for this purpose (not a subdomain with a CNAME setting, etc.), and have created a simple PHP file for testing the difference in retrieval time for grabbing image files, in this case the same image 10,000 times:
<?php
echo '<!DOCTYPE html>';
// Here I can toggle between grabbing the static content from the static domain with the specially edited .htaccess file, or from the main domain, just by remming out one line and unremming the other:
$source = "http://MY-STATIC-DOMAIN.com/";
//$source = "http://MY-DYNAMIC-DOMAIN.COM/"
$before = microtime(true);
$output = '<img style="display: none;" src="' . $source . 'images/TEST-IMAGE.jpeg " height="400" width="311"/>';
for ($i=0 ; $i<10000 ; $i++) {
echo $output;
}
$after = microtime(true);
$timex = ($after-$before);
echo $timex;
?>
The trick is to configure the static domain NOT to receive cookies (RIGHT?) Better yet would be a way to configure the origin/dynamic domain not to SEND cookies, but I can't see a way to do that on a case-by-case basis (or especially with any inline code, which would seem to be ideal...there's a third-party web proxy called PRIVOXY that would seem to offer this benefit, but I'd prefer not to have to rely on anything that I could simply code directly in the .htaccess file).
In any case, there's only scant information online about how to do this by editing the .htaccess file of the STATIC domain, and the suggested code for the .htaccess file runs from the incredibly simple:
Header unset Cookie
Header unset Set-Cookie
...to the mind-bendingly complex:
# Use Mod_deflate to compress static files
<ifmodule mod_deflate.c>
<filesmatch ".(js|css|ico|txt|htm|html|php)$">
SetOutputFilter DEFLATE
</filesmatch>
</ifmodule>
# Speed up caching
FileETag MTime Size
# Expires
ExpiresActive On
ExpiresDefault "access plus 366 days"
# Future Expires Headers
<filesmatch ".(ico|pdf|flv|jpg|jpeg|png|gif|js|css|swf)$">
Header set Expires "Sat, 27 Dec 2014 23:59:59 GMT"
</filesmatch>
Yet, no matter which instructions I place into the .htaccess file of the STATIC domain that is housing the JPEG file that I'm calling repeatedly in my test, the time difference is neglible, and in some cases retrieving the static content from the origin/dynamic site is faster.
Have I devised my test file incorrectly? Or is there a better set of .htaccess instructions than the two competing ones above (and I've found others...I've been testing this for hours, both on my local server and on my live sites).
I've also read the study in which it seemed proven that serving minified .CSS files from the primary domain itself is faster than retrieving them from a static domain, but the author concedes at the conclusion of the article that images are still best served from a static domain:
http://www.jonathanklein.net/2014/02/revisiting-cookieless-domain.html
Many thanks in advance from any guru who can point me in the right direction (especially as regards not sending out a cookie with the content request in the first place, which would benefit from an in-line command in the HTML, I would reckon).