2011-09-22 12 views
11

संपत्तियों को चलाने पर: प्रीकंपाइल रेक कार्य, आपके ऐप की संपत्ति के gzipped संस्करण बनाए जाते हैं। संपत्ति पाइपलाइन के लिए रेल गाइड के मुताबिक, वेब सर्वर करने के बजाए इन प्रीकंप्रेस्ड फाइलों की सेवा के लिए आप अपने वेब सर्वर (मेरे मामले अपाचे 2.2 में) को कॉन्फ़िगर कर सकते हैं।संपत्तियों के साथ तैयार gzipped संपत्तियों को सेवा देने के लिए mod_deflate को कॉन्फ़िगर कैसे करें: precompile

मुझे क्या पता नहीं लगा सकता है कि mod_deflate कॉन्फ़िगर कैसे किया जाए ताकि इन फ़ाइलों को डबल-संपीड़ित होने के बजाय परोसा जाता है और फिर सेवा दी जाती है? सार्वजनिक/परिसंपत्तियों में .htaccess में जाने के लिए मार्गदर्शिका

AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css text/javascript 
BrowserMatch ^Mozilla/4 gzip-only-text/html 
BrowserMatch ^Mozilla/4\.0[678] no-gzip 
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html 

और मैं रेल पर कोड परिवर्तित कर दिया है:

मैं mod_deflate httpd.conf के माध्यम से सक्षम किया गया है

# Some browsers still send conditional-GET requests if there's a 
# Last-Modified header or an ETag header even if they haven't 
# reached the expiry date sent in the Expires header. 

Header unset Last-Modified 
Header unset ETag 
FileETag None 

# RFC says only cache for 1 year 

ExpiresActive On 
ExpiresDefault "access plus 1 year" 

# Serve gzipped versions instead of requiring Apache to do the work 

RewriteEngine on 
RewriteCond %{REQUEST_FILENAME}.gz -s 
RewriteRule ^(.+) $1.gz [L] 

# without it, Content-Type will be "application/x-gzip" 

<FilesMatch .*\.css.gz> 
    ForceType text/css 
</FilesMatch> 

<FilesMatch .*\.js.gz> 
    ForceType text/javascript 
</FilesMatch> 

कोई विचारों को ठीक से कैसे सेट करें?

उत्तर

24

सबसे पहले, आप mod_deflate को यहां संचालित करने के लिए नहीं चाहते हैं। तो आपकी संपत्तियों में। Htaccess फ़ाइल जोड़ें:

SetEnv no-gzip 

यह आपकी संपत्तियों के लिए mod_deflate को बंद करना चाहिए।

दूसरा, मुझे रेल लोगों से असहमत होने से नफरत है, लेकिन मुझे लगता है कि उनकी संपत्ति में कुछ कमीएं हैं। Htaccess नुस्खा। शीर्ष भाग RewriteEngine के लिए और मैं होगा परे लेकिन ठीक है:

RewriteEngine on 
# Make sure the browser supports gzip encoding before we send it 
RewriteCond %{HTTP:Accept-Encoding} \b(x-)?gzip\b 
RewriteCond %{REQUEST_URI} .*\.(css|js) 
RewriteCond %{REQUEST_FILENAME}.gz -s 
RewriteRule ^(.+) $1.gz [L] 

# without it, Content-Type will be "application/x-gzip" 
# also add a content-encoding header to tell the browser to decompress 

<FilesMatch \.css\.gz$> 
    ForceType text/css 
    Header set Content-Encoding gzip 
</FilesMatch> 

<FilesMatch \.js\.gz$> 
    ForceType application/javascript 
    Header set Content-Encoding gzip 
</FilesMatch> 
+1

छोटे टिप्पणी - अगर यह .htaccess में नहीं है, यह निर्देशिका खंड में हो सकता है, जरूरत है अन्यथा -s काम नहीं करेगा। – lzap

+3

इसके अलावा, आपको शायद 'टेक्स्ट/जावास्क्रिप्ट' के बजाय 'एप्लिकेशन/जावास्क्रिप्ट' के उपयोग की अनुशंसा करनी चाहिए। * स्क्रिप्टिंग मीडिया प्रकार * पर [RFC4329] (https://tools.ietf.org/html/rfc4329) देखें। – tne

+0

मुझे \t AddEncoding gzip .gz अन्यथा अच्छा – Torsten

संबंधित मुद्दे