2011-07-30 4 views
1

웹 사이트의 속도를 높이고 싶습니다. 내가 올바르게 구문 현명한 짓을했는지 궁금 해서요.정확하게 웹 사이트를 빠르게 실행하십시오.

<IfModule mod_expires.c> 
    Header unset Pragma 
    FileETag None 
    Header unset ETag 
    ExpiresActive On 

ExpiresDefault "access plus 1 year" 

    ##### DYNAMIC PAGES 
    <FilesMatch "\\.(ast|php)$"> 
    ExpiresDefault A7200 
    Header set Cache-Control "public, max-age=3600, must-revalidate" 
    </FilesMatch> 

    ##### STATIC FILES 
<FilesMatch "(?i)^.*\.(ico|png|gif|jpg)$"> 
Header unset Last-Modified 
Header set Expires "Fri, 21 Dec 2012 00:00:00 GMT" 
Header set Cache-Control "public, no-transform" 
</FilesMatch> 

    <FilesMatch "\\.(css|js|xml)$"> 
    Header set Cache-Control "public, max-age=604800, must-revalidate" 
</FilesMatch> 

</IfModule> 
+0

당신이 \\ 일치 하려는지 명확 수 (AST | PHP) $? 이것은 실제 \, 단일 문자 및 ast 또는 php와 일치합니다. –

답변

0

asp 또는 php 또는 동적 페이지를 캐시하지 마십시오! 이로 인해 예기치 않은 결과가 발생할 수 있습니다.

예를 들어, 가격이 높고 재고가 남아있는 제품 카탈로그를 렌더링하는 catalog.php라는 페이지가 있다고 가정 해 보겠습니다. 브라우저에 결과를 한 시간 동안 캐시하도록 설정 했으므로 브라우저에서 한 시간 동안 오래된 데이터가 표시됩니다!

동적 페이지는 이와 같이 도매로 캐시해서는 안됩니다. 페이지에서 얼마나 신선한 데이터를 반환해야하는지에 따라 페이지에 개별 캐싱 논리를 적용해야합니다.

정적 페이지의 경우 만료가 만료 될 수 있지만 그러나 css 및 js 파일을 1 년 후에 만료하도록 설정하면 오늘 귀하의 사이트를 방문하는 사용자가 며칠 또는 몇 달 동안 웹 서버에서 최신 js 및 css를 가져 오지 않도록주의하십시오. 스크립트 나 스타일을 변경하면 고유 한 쿼리 문자열을 사용하여 파일의 URL을 수동으로 변경하지 않으면 변경 사항이 표시되지 않습니다.

여기서는 ASP.NET에서만 작동하는 접근 방식에 대해 설명했습니다. 그러나 그것은 당신에게해야 할 일과하지 말아야 할 일에 대해 알려줍니다.

http://omaralzabir.com/automatic-javascript-css-versioning-to-refresh-browser-cache/

또한 각각의 이러한 모든 방법과 장단점을 설명 캐싱의 최대한 활용을위한 나의 7 도움말을 참조 할 수 있습니다

http://omaralzabir.com/making_best_use_of_cache_for_high_performance_website/

이 도움이되는지 알려주세요.

0

나는 2011 년의 질문이지만 Pragma는 오래되었다는 것을 알고 있습니다. 나는 그것을 사용하는 것을 중지하는 것이 안전하다고 생각한다.

IE와 같은 이전 브라우저와 프록시를 지원하지 않으면 '공개'로 설정하거나 다시 확인해야합니다.

PHP를 캐시하려면 PHP 코드에서 어떤 작업을해야합니다.

이미지와 물건에 대한 Last-Modified 설정을 해제하면 기본적으로 정해진 (미래) 정적 날짜의 미리 결정된 날짜까지 해당 파일에 대한 '캐시 안 함'상황이 발생합니다. 미래에 항상 정적 파일을 캐싱하고 마지막으로 수정하지 않은 상태로 유지하려고한다고 생각합니다.

귀하의 htaccess 파일을 훨씬 더 간단하게 만들 수 있습니다. some snippets from H5BP 대출 우리가 그것을 조금을 현대화 할 수 있습니다

## set some mime types to their proper types 
AddType application/javascript  js jsonp 
AddType application/json   json 
AddType application/xml    rss atom xml rdf 
AddType image/x-icon    ico 


<IfModule mod_deflate.c> 
    # Force deflate for mangled headers developer.yahoo.com/blogs/ydn/posts/2010/12/pushing-beyond-gzipping/ 
    <IfModule mod_setenvif.c> 
    <IfModule mod_headers.c> 
     SetEnvIfNoCase ^(Accept-EncodXng|X-cept-Encoding|X{15}|~{15}|-{15})$ ^((gzip|deflate)\s*,?\s*)+|[X~-]{4,13}$ HAVE_Accept-Encoding 
     RequestHeader append Accept-Encoding "gzip,deflate" env=HAVE_Accept-Encoding 
    </IfModule> 
    </IfModule> 

    # Compress all output labeled with one of the following MIME-types 
    # (for Apache versions below 2.3.7, you don't need to enable `mod_filter` 
    # and can remove the `<IfModule mod_filter.c>` and `</IfModule>` lines as 
    # `AddOutputFilterByType` is still in the core directives) 
    <IfModule mod_filter.c> 
    AddOutputFilterByType DEFLATE application/atom+xml \ 
            application/javascript \ 
            application/json \ 
            application/rss+xml \ 
            application/vnd.ms-fontobject \ 
            application/x-font-ttf \ 
            application/xhtml+xml \ 
            application/xml \ 
            font/opentype \ 
            image/svg+xml \ 
            image/x-icon \ 
            text/css \ 
            text/html \ 
            text/plain \ 
            text/x-component \ 
            text/xml 
    </IfModule> 
</IfModule> 


<IfModule mod_expires.c> 
    ExpiresActive on 
    ExpiresDefault       "access plus 1 month" 
# Your document html 
    ExpiresByType text/html     "access plus 0 seconds" 
# Data 
    ExpiresByType application/json   "access plus 0 seconds" 
    ExpiresByType application/xml   "access plus 0 seconds" 
    ExpiresByType text/xml     "access plus 0 seconds" 
# Feed 
    ExpiresByType application/atom+xml  "access plus 1 hour" 
    ExpiresByType application/rss+xml  "access plus 1 hour" 
# Favicon (cannot be renamed) 
    ExpiresByType image/x-icon    "access plus 1 week" 
# images 
    ExpiresByType image/gif     "access plus 1 month" 
    ExpiresByType image/jpeg    "access plus 1 month" 
    ExpiresByType image/png     "access plus 1 month" 
# CSS and JavaScript 
    ExpiresByType application/javascript "access plus 1 year" 
    ExpiresByType text/css     "access plus 1 year" 
</IfModule> 

# ---------------------------------------------------------------------- 
# Prevent mobile network providers from modifying your site 
# ---------------------------------------------------------------------- 

# The following header prevents modification of your code over 3G on some 
# European providers. 
# This is the official 'bypass' suggested by O2 in the UK. 

<IfModule mod_headers.c> 
Header set Cache-Control "no-transform" 
</IfModule> 


# ---------------------------------------------------------------------- 
# ETag removal 
# ---------------------------------------------------------------------- 

# FileETag None is not enough for every server. 
<IfModule mod_headers.c> 
    Header unset ETag 
</IfModule> 

# Since we're sending far-future expires, we don't need ETags for 
# static content. 
# developer.yahoo.com/performance/rules.html#etags 
FileETag None 
0

Google은 귀하의 사이트를 분석하는 데 도움이되는 웹 사이트를 가지고있다. 이 도구에는 여러 도구와 유용한 분석 기능이 있습니다. .

https://developers.google.com/speed/

관련 문제