Drupal 7 dan PageSpeed


13

PageSpeed modul Apache menyediakan berbagai optimisasi untuk HTML, JavaScript dan lainnya, yang sangat bagus.

Namun, beberapa fitur-fiturnya berlebihan dengan metode agregasi dan optimisasi Drupal sendiri. Jadi, adakah yang menguji filter mana yang akan berguna untuk situs web Drupal 7 yang khas dan mana yang tidak berguna karena Drupal sudah memberikan dukungan untuknya?


Lebih jauh, apakah lebih menarik untuk membiarkan PageSpeed ​​atau Drupal menangani agregasi JS / CSS?
wildpeaks

Jawaban:


9

Ini adalah bagian PageSpeed ​​dari .htaccess saya:

<IfModule pagespeed_module>
    ModPagespeed on
    ModPagespeedEnableFilters extend_cache
    ModPagespeedEnableFilters collapse_whitespace
    ModPagespeedEnableFilters combine_css
    ModPagespeedEnableFilters move_css_to_head
    ModPagespeedEnableFilters remove_comments
    ModPagespeedEnableFilters inline_css
    ModPagespeedEnableFilters rewrite_javascript
    ModPagespeedEnableFilters insert_img_dimensions
    ModPagespeedEnableFilters rewrite_images
    ModPagespeedEnableFilters rewrite_css
</IfModule>

Sementara ada sedikit tumpang tindih dengan kompresi js dan css, saya tidak melihat hasil negatif. Saya telah menetapkan Drupal 7 untuk menggabungkan dan mengompresi CSS dan JS.

Situs ini bukan lalu lintas sangat tinggi.


Anda juga dapat memuat filter pada satu baris tetapi saya lebih suka keterbacaan melakukannya dengan cara ini.
Chris Hawes

Sesuai kode.google.com/speed/page-speed/docs/... Anda harus menggunakan sekarang insert_image_dimensions, karena insert_img_dimensions sudah tidak digunakan lagi. Juga saya mengerti rewrite_images adalah superset, yang mencakup insert_img_dimensions
john

-1

Berikut ini adalah pengaturan htaccess saya:

# -----------------------------------------------------------------------
# Enable keep-alive for faster pagespeed:
# -----------------------------------------------------------------------
<ifModule mod_headers.c> 
    Header set Connection keep-alive 
</ifModule>

# -----------------------------------------------------------------------
# Expire caching
# -----------------------------------------------------------------------
<IfModule mod_expires.c>
    ExpiresActive On
    ExpiresByType image/jpg "access plus 1 year"
    ExpiresByType image/jpeg "access plus 1 year"
    ExpiresByType image/gif "access plus 1 year"
    ExpiresByType image/png "access plus 1 year"
    ExpiresByType text/css "access plus 1 month"
    ExpiresByType application/pdf "access plus 1 month"
    ExpiresByType application/x-font-woff "access plus 1 year"
    ExpiresByType application/x-font-woff2 "access plus 1 year"
    ExpiresByType application/x-font-ttf  "access plus 1 year"
    ExpiresByType text/x-javascript "access plus 1 month"
    ExpiresByType application/x-shockwave-flash "access plus 1 month"
    ExpiresByType image/x-icon "access plus 1 year"
    ExpiresDefault "access plus 2 days"
</IfModule>

# -----------------------------------------------------------------------
# Cache Headers
# -----------------------------------------------------------------------
<ifmodule mod_headers.c>
  # Cache specified files for 31 days
  <filesmatch "\.(ico|flv|jpg|jpeg|png|gif|css|swf)$">
  Header set Cache-Control "max-age=2678400, public"
  </filesmatch>
  # Cache HTML files for a couple hours
  <filesmatch "\.(html|htm)$">
  Header set Cache-Control "max-age=7200, private, must-revalidate"
  </filesmatch>
  # Cache PDFs for a day
  <filesmatch "\.(pdf)$">
  Header set Cache-Control "max-age=86400, public"
  </filesmatch>
  # Cache Javascripts for 31 days
  <filesmatch "\.(js)$">
  Header set Cache-Control "max-age=2678400, private"
  </filesmatch>
</ifmodule>

# -----------------------------------------------------------------------
# Defining MIME types to ensure the web server actually knows about them.
# -----------------------------------------------------------------------
<IfModule mod_mime.c>
    AddType text/css .css
    AddType application/javascript .js
    AddType application/x-javascript .js
    AddType text/html .html .htm
    AddType text/richtext .rtf .rtx
    AddType image/svg+xml .svg .svgz
    AddType text/plain .txt
    AddType text/xsd .xsd
    AddType text/xsl .xsl
    AddType text/xml .xml
    AddType video/asf .asf .asx .wax .wmv .wmx
    AddType video/avi .avi
    AddType image/bmp .bmp
    AddType application/java .class
    AddType video/divx .divx
    AddType application/msword .doc .docx
    AddType application/x-msdownload .exe
    AddType image/gif .gif
    AddType application/x-gzip .gz .gzip
    AddType image/x-icon .ico
    AddType image/jpeg .jpg .jpeg .jpe
    AddType application/vnd.ms-access .mdb
    AddType audio/midi .mid .midi
    AddType video/quicktime .mov .qt
    AddType audio/mpeg .mp3 .m4a
    AddType video/mp4 .mp4 .m4v
    AddType video/mpeg .mpeg .mpg .mpe
    AddType application/vnd.ms-project .mpp
    AddType application/vnd.oasis.opendocument.database .odb
    AddType application/vnd.oasis.opendocument.chart .odc
    AddType application/vnd.oasis.opendocument.formula .odf
    AddType application/vnd.oasis.opendocument.graphics .odg
    AddType application/vnd.oasis.opendocument.presentation .odp
    AddType application/vnd.oasis.opendocument.spreadsheet .ods
    AddType application/vnd.oasis.opendocument.text .odt
    AddType audio/ogg .ogg
    AddType application/pdf .pdf
    AddType image/png .png
    AddType application/vnd.ms-powerpoint .pot .pps .ppt .pptx
    AddType audio/x-realaudio .ra .ram
    AddType application/x-shockwave-flash .swf
    AddType application/x-tar .tar
    AddType image/tiff .tif .tiff
    AddType audio/wav .wav
    AddType audio/wma .wma
    AddType application/vnd.ms-write .wri
    AddType application/vnd.ms-excel .xla .xls .xlsx .xlt .xlw
    AddType application/zip .zip
    AddEncoding gzip svgz
    #AddEncoding gzip js
    #AddEncoding gzip  css
</Ifmodule>

# -----------------------------------------------------------------------
# Compressing output.
# -----------------------------------------------------------------------
<IfModule mod_deflate.c>
    # Enable compression
    SetOutputFilter DEFLATE

    # Don't compress images
    SetEnvIfNoCase Request_URI \.(?:gif|png|jpg|jpeg)$ no-gzip dont-vary
    Header append Vary User-Agent env=!dont-vary    
</IfModule>

# -----------------------------------------------------------------------
#  PageSpeed. - TESTED with Mediacenter
# -----------------------------------------------------------------------
<IfModule pagespeed_module>

    # Turn on mod_pagespeed. To completely disable mod_pagespeed, you
    # can set this to "off".
    ModPagespeed on

    # Direct Apache to send all HTML output to the mod_pagespeed
    # output handler.
    AddOutputFilterByType MOD_PAGESPEED_OUTPUT_FILTER text/html

    ModPagespeedLowercaseHtmlNames on
    ModPagespeedEnableFilters extend_cache
    ModPagespeedEnableFilters insert_dns_prefetch
    ModPagespeedEnableFilters add_head
    ModPagespeedEnableFilters add_instrumentation
    ModPagespeedEnableFilters make_google_analytics_async
    #ModPagespeedEnableFilters make_show_ads_async
    ModPagespeedEnableFilters flatten_css_imports

#
# Text / HTML
#

    ModPagespeedEnableFilters collapse_whitespace
    ModPagespeedEnableFilters convert_meta_tags
    ModPagespeedEnableFilters remove_comments
    ModPagespeedEnableFilters collapse_whitespace
    ModPagespeedEnableFilters elide_attributes
    ModPagespeedEnableFilters trim_urls
    ModPagespeedEnableFilters pedantic

#
# JavaScript
#

    ModPagespeedEnableFilters combine_javascript
    #ModPagespeedEnableFilters canonicalize_javascript_libraries
    ModPagespeedEnableFilters rewrite_javascript
    ModPagespeedEnableFilters defer_javascript
    ModPagespeedEnableFilters inline_javascript

#
# CSS
#

    ModPagespeedEnableFilters rewrite_css
    ModPagespeedEnableFilters combine_css
    ModPagespeedEnableFilters move_css_to_head
    ModPagespeedEnableFilters inline_css
    ModPagespeedEnableFilters inline_import_to_link
    ModPagespeedEnableFilters move_css_above_scripts

#
# Images
#

    ModPagespeedEnableFilters inline_preview_images
    ModPagespeedEnableFilters insert_img_dimensions
    ModPagespeedEnableFilters rewrite_images
    ModPagespeedEnableFilters convert_gif_to_png
    ModPagespeedEnableFilters recompress_images
    ModPagespeedEnableFilters recompress_jpeg
    ModPagespeedEnableFilters recompress_png
    ModPagespeedEnableFilters convert_jpeg_to_progressive
    ModPagespeedEnableFilters resize_mobile_images
    ModPagespeedEnableFilters sprite_images
    ModPagespeedEnableFilters lazyload_images
    ModPagespeedEnableFilters local_storage_cache
    ModPagespeedJpegRecompressionQuality 100
    #ModPagespeedEnableFilters responsive_images
    ModPagespeedEnableFilters resize_images

    # Disallow problematic files:
    #ModPagespeedDisallow "*/respond.js"
    #ModPagespeedDisallow "*/lightbox.js*"  

</IfModule>         
Dengan menggunakan situs kami, Anda mengakui telah membaca dan memahami Kebijakan Cookie dan Kebijakan Privasi kami.
Licensed under cc by-sa 3.0 with attribution required.