2011-07-30 5 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というページがあるとします。ブラウザに結果を1時間キャッシュするように設定しているので、1時間ブラウザの古いデータが表示されます!

ダイナミックページをこのように卸売することは決してありません。ページからのデータの返送方法に基づいて、個々のキャッシングロジックをページに配置する必要があります。

静的ページの場合、このような賞味期限を過ぎることはできますが、ただし、cssファイルとjsファイルを1年後に期限切れに設定すると、今日あなたのサイトにアクセスしたユーザーは、Webサーバーから最新の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年からの質問ですが、それでもプラグマは古いです。私はそれを使用するのをやめても安全だと思います。

私たちはめったに「public」を設定する必要はありません。また、IEv4以前のような実際に古いブラウザやプロキシをサポートしようとしている場合を除き、revalidateする必要はありません。

もしあなたのPHPをキャッシュするつもりなら、あなたはまだあなたのPHPコードでいくつかの作業を行う必要があります。

最終更新日時に画像と物事の設定を解除すると、基本的に、その時点の静的(予定)の予定日までこれらのファイルに「キャッシュしない」状態が発生します。私は静的なファイルをX日後にキャッシュし、最後に変更を解除しないことを望むと思います。

あなたの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/

関連する問題