doulierong0334 2015-09-05 22:01 采纳率: 100%
浏览 35

配置无Cookie域以提供静态内容的2015方法是什么?

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).

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 R语言Rstudio突然无法启动
    • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
    • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
    • ¥15 用windows做服务的同志有吗
    • ¥60 求一个简单的网页(标签-安全|关键词-上传)
    • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
    • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
    • ¥100 为什么这个恒流源电路不能恒流?
    • ¥15 有偿求跨组件数据流路径图
    • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值