缓存 twitter、facebook、gplus javascript
由于谷歌页面速度工具的建议,我正在尝试优化我的网站。它告诉我要为这些文件“利用浏览器缓存”; `
http://cdn.api.twitter.com/.../count.json?... (3.6 minutes)
http://cdn.api.twitter.com/.../count.json?... (3.6 minutes)
http://cdn.api.twitter.com/.../count.json?... (5.2 minutes)
http://cdn.api.twitter.com/.../count.json?... (13.2 minutes)
http://cdn.api.twitter.com/.../count.json?... (14 minutes)
http://cdn.api.twitter.com/.../count.json?... (14.5 minutes)
http://cdn.api.twitter.com/.../count.json?... (14.9 minutes)
http://cdn.api.twitter.com/.../count.json?... (15 minutes)
http://cdn.api.twitter.com/.../count.json?... (15 minutes)
http://static.ak.fbcdn.net/connect.php/css/share-button-css (16.8 minutes)
http://static.ak.fbcdn.net/connect.php/js/FB.Share (18.3 minutes)
http://connect.facebook.net/tr_TR/all.js (19 minutes)
http://platform.twitter.com/widgets.js (30 minutes)
https://apis.google.com/js/plusone.js (60 minutes)
` 我知道如何在 .htaccess 文件中使用 mod_expires.c 缓存我自己的 js、css 文件,但不明白如何缓存这些文件?
这是我的 .htaccess 文件 `
# BEGIN Compress text files
<ifModule mod_deflate.c>
AddOutputFilterByType DEFLATE text/html text/plain text/xml application/xml application/xhtml+xml text/css text/javascript application/javascript application/x-javascript
</ifModule>
# END Compress text files
# BEGIN Expire headers
<ifModule mod_expires.c>
ExpiresActive On
ExpiresDefault "access plus 5 seconds"
ExpiresByType image/x-icon "access plus 2592000 seconds"
ExpiresByType image/jpeg "access plus 2592000 seconds"
ExpiresByType image/png "access plus 2592000 seconds"
ExpiresByType image/gif "access plus 2592000 seconds"
ExpiresByType application/x-shockwave-flash "access plus 2592000 seconds"
ExpiresByType text/css "access plus 604800 seconds"
ExpiresByType text/javascript "access plus 604800 seconds"
ExpiresByType application/javascript "access plus 604800 seconds"
ExpiresByType application/x-javascript "access plus 604800 seconds"
ExpiresByType text/html "access plus 600 seconds"
ExpiresByType application/xhtml+xml "access plus 600 seconds"
</ifModule>
# END Expire headers
# BEGIN Cache-Control Headers
<ifModule mod_headers.c>
<filesMatch "\.(ico|jpe?g|png|gif|swf)$">
Header set Cache-Control "public"
</filesMatch>
<filesMatch "\.(css)$">
Header set Cache-Control "public"
</filesMatch>
<filesMatch "\.(js)$">
Header set Cache-Control "private"
</filesMatch>
<filesMatch "\.(x?html?|php)$">
Header set Cache-Control "private, must-revalidate"
</filesMatch>
</ifModule>
# END Cache-Control Headers
# BEGIN Turn ETags Off
FileETag None
# END Turn ETags Off
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://domain.com/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://domain.com$ [NC]
RewriteCond %{HTTP_REFERER} !^http://www.domain.com/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://www.domain.com$ [NC]
RewriteRule .*\.(jpg|jpeg|gif|png|bmp)$ - [F,NC]
`
I am trying to optimize my site due to the suggestions that google's pagespeed tool. it says me to make "Leverage browser caching" for these files;
`
http://cdn.api.twitter.com/.../count.json?... (3.6 minutes)
http://cdn.api.twitter.com/.../count.json?... (3.6 minutes)
http://cdn.api.twitter.com/.../count.json?... (5.2 minutes)
http://cdn.api.twitter.com/.../count.json?... (13.2 minutes)
http://cdn.api.twitter.com/.../count.json?... (14 minutes)
http://cdn.api.twitter.com/.../count.json?... (14.5 minutes)
http://cdn.api.twitter.com/.../count.json?... (14.9 minutes)
http://cdn.api.twitter.com/.../count.json?... (15 minutes)
http://cdn.api.twitter.com/.../count.json?... (15 minutes)
http://static.ak.fbcdn.net/connect.php/css/share-button-css (16.8 minutes)
http://static.ak.fbcdn.net/connect.php/js/FB.Share (18.3 minutes)
http://connect.facebook.net/tr_TR/all.js (19 minutes)
http://platform.twitter.com/widgets.js (30 minutes)
https://apis.google.com/js/plusone.js (60 minutes)
`
i know how to cache my own js,css files with mod_expires.c in .htaccess file but didnt understand how to cache those ?
and here is my .htaccess file
`
# BEGIN Compress text files
<ifModule mod_deflate.c>
AddOutputFilterByType DEFLATE text/html text/plain text/xml application/xml application/xhtml+xml text/css text/javascript application/javascript application/x-javascript
</ifModule>
# END Compress text files
# BEGIN Expire headers
<ifModule mod_expires.c>
ExpiresActive On
ExpiresDefault "access plus 5 seconds"
ExpiresByType image/x-icon "access plus 2592000 seconds"
ExpiresByType image/jpeg "access plus 2592000 seconds"
ExpiresByType image/png "access plus 2592000 seconds"
ExpiresByType image/gif "access plus 2592000 seconds"
ExpiresByType application/x-shockwave-flash "access plus 2592000 seconds"
ExpiresByType text/css "access plus 604800 seconds"
ExpiresByType text/javascript "access plus 604800 seconds"
ExpiresByType application/javascript "access plus 604800 seconds"
ExpiresByType application/x-javascript "access plus 604800 seconds"
ExpiresByType text/html "access plus 600 seconds"
ExpiresByType application/xhtml+xml "access plus 600 seconds"
</ifModule>
# END Expire headers
# BEGIN Cache-Control Headers
<ifModule mod_headers.c>
<filesMatch "\.(ico|jpe?g|png|gif|swf)$">
Header set Cache-Control "public"
</filesMatch>
<filesMatch "\.(css)$">
Header set Cache-Control "public"
</filesMatch>
<filesMatch "\.(js)$">
Header set Cache-Control "private"
</filesMatch>
<filesMatch "\.(x?html?|php)$">
Header set Cache-Control "private, must-revalidate"
</filesMatch>
</ifModule>
# END Cache-Control Headers
# BEGIN Turn ETags Off
FileETag None
# END Turn ETags Off
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://domain.com/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://domain.com$ [NC]
RewriteCond %{HTTP_REFERER} !^http://www.domain.com/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://www.domain.com$ [NC]
RewriteRule .*\.(jpg|jpeg|gif|png|bmp)$ - [F,NC]
`
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
除非您制作副本并将其托管在您控制的域上,否则您无法缓存这些内容。
You can't cache those unless you make copies and host them on a domain you control.