Drupal在Google PageSpeed Insights 評價高分的方法

最近在Adsense的後台,發現網站狀態的分數只有1分 (滿分5分)

於是研究了一下取得高分的方法

能做的方式就是先壓縮css及js

我們必需取得 Advanced CSS/JS Aggregation 這個模組,接著照 Google 找到的資料照作即可


How to get a high pagespeed score
  1. Go to admin/config/development/performance/advagg
    • Uncheck "Use cores grouping logic"
    • Check "Combine CSS files by using media queries"
  2. Install AdvAgg Modifier if not enabled and go to admin/config/development/performance/advagg/mod
    • Under "Move JS to the footer" select "All"
    • Set "Enable preprocess on all JS" and "Enable preprocess on all CSS"
    • Enable every checkbox under both "Optimize JavaScript Ordering" and "Optimize CSS Ordering"

Other things to consider

On the admin/config/development/performance/advagg/mod page
  • There is the setting "Remove unused JavaScript tags if possible". This is a backport of D8 where it will not add any JS to the page if it is not being used (https://drupal.org/node/1279226).
  • AdvAgg Mod will also convert all async script tags to be compatible with older browser as long as "Rewrite asynchronous script tags to inline, old-browser-compatible scripts" is checked.
  • There is an experimental setting under "Experimental Settings -> Deferred JavaScript Execution: Add The defer Tag To All Script Tags" which will load JS in a less blocking way than it is normally done (http://peter.sh/experiments/asynchronous-and-deferred-javascript-execution-explained/). This setting should have a similar affect to moving all JS to the footer without having to do so.
AdvAgg Bundler settings are at admin/config/development/performance/advagg/bundler. The bundler provides intelligent bundling of CSS and JS files by grouping files that belong together. This does what core tried to do; group CSS & JS files together that get used together. Using this will make your pagespeed score go down as there will be more css/js files to download but if different css/js files are used on different pages of your site this will be a net win as a new full aggregate will not have to be downloaded, instead a smaller aggregate can be downloaded, ideally with only the css/js that is different on that page. You can select how many bundles to create and the bundler will do it's best to meet that goal; if using browser css/js conditionals (js browser conditionals backported from D8https://drupal.org/node/865536) then the bundler might not meet your set value.
If you have a landing page with minimal CSS/JS you can use AdvAgg Mod to inline all CSS/JS on that page. 99.9% of sites will not need this but I kept getting requests for this feature so I built it. On the admin/config/development/performance/advagg/mod page under "Inline CSS/JS on specific pages" you can add in pages that you wish to have all CSS & JS inlined. This tool is for laser precision as if it is used incorrectly your sites performance will suffer.

留言

熱門文章