ADVANCED CSS/JS AGGREGATION MODULE

CONTENTS

CORE FEATURES & BENEFITS

SUBMODULE OVERVIEW

AdvAgg comes with quite a few submodules to do various tasks. Most are compatible with the vast majority of other mods but some may have conflicts. If so those are noted here and more details in the module's full write-ups.

AdvAgg Cdn (advagg_cdn)

This module may have conflicts, but only with other CDN type modules.

Load CSS or JavaScript libraries from a public CDN; currently only supports jQuery and jQuery UI with either Google's or Microsoft's CDN.

AdvAgg CSS/JS Validator (advagg_validator)

Validate CSS and or JS files in your site through a few different validators.

AdvAgg External Minifier (advagg_ext_minify)

Minify CSS or JS through an otherwise unsupported method, with a configurable command line.

AdvAgg Minify CSS (advagg_css_minify)

Minify the CSS files using a 3rd party minifier; currently supports YUI (included) or the Core minification algorithm.

AdvAgg Minify JS (advagg_js_minify)

Compress the compiled JavaScript files using a 3rd party minifier; built in support for a number of minifiers.

AdvAgg Modifier (advagg_mod):

Depending on tweaks applied this module may cause compatibility issues with other modules.

Includes additional tweaks that may not work for all sites such as: - Force preprocessing for all CSS/JS. - Add defer tag to all JS. - Defer CSS loading using rel=preload and JavaScript Polyfill. - Add async tag to all or only local JavaScript.

AdvAgg Old IE Compatibility Enhancer (advagg_old_ie_compatibility)

This module may have conflicts with other modules if it is enabled.

Includes additional functionality to improve Drupal compatibility with old versions of Internet Explorer (6-9).

CONFIGURATION

Settings page is located at: admin/config/development/performance/advagg.

Global Options

Compression Options

CSS Options

JS Options

CRON Options

Unless you have a good understanding of what you are trying to do, probably better to leave these alone. For best performance, setting up an external cron task is better than relying on Drupal's built in "poor man's cron".

Obscure Options

Information page

Located at admin/config/development/performance/advagg/info. This page provides debugging information. There are no configuration options here.

Operations page

Located at admin/config/development/performance/advagg/operations. This is a collection of commands to control the cache and manage testing of this module. In general this page is useful when troubleshooting some aggregation issues.

Drastic Measures

Developing your site with Advanced Agreggates

With the new architecture, Advanced Agreggates is much more intelligent when in development. It will detect changed files, however, depending on settings it may not be instant. Also, repeatedly optimizing a file for every minor change when doing stylesheets or JavaScript isn't the most efficient option. So, what can you do? If just one site instance (questionable but budgets etc), you may want to just adjust the configuration to refresh caches a bit faster or disable AdvAgg temporarily while doing heavy development.

That will work but, there are a few other methods that will work better for some work flows especially if doing config import and export.

Temporarily Disabling AdvAgg

  1. Via a local.settings.php. Often developers will disable core asset aggregation ith config overrides or enable various core development features. You can do the same to disable AdvAgg. For example some users use the following lines:

    // Disable Core CSS and JS aggregation.
    $config['system.performance']['css']['preprocess'] = FALSE;
    $config['system.performance']['js']['preprocess'] = FALSE;
    
    // Disable AdvAgg.
    $config['advagg.settings']['enabled'] = FALSE;
  2. Via main config page, un-check Enable Advanced Aggregates. This will take effect right away for all users.

  3. Via the AdvAgg url parameter. Not as reliable depending on various system caches. To use, just append ?advagg=0 to your url.

  4. Using the browser cookie function from the Operations page. Similar to the url parameter this isn't as good as the first 2 options.

SERVER SETTINGS

AdvAgg can adjust configuration to improve performance for Apache servers. It does that through .htaccess files. There are reasons not to use .htaccess, however for most sites those aren't an important issue as it is a performance fine tuning issue. However for non-apache servers, .htaccess files don't work and in the case of Nginx, there is no equivalent. Instead Nginx has all such configuration within the server/vhost definition.

So if you're using Nginx read on for instructions on adding those to your vhost or server settings. All of the below snippets go within the server { } block in your config files.

Cache Control Immutable

The immutable cache control header is a fairly new header. Only Firefox & Edge currently support it as of September 2017. Browsers that don't support it will ignore so it is safe to enable.

To enable in nginx add the following to your server configuration:

   location ~ ^/sites/.*/files/(css|js)/optimized {
     add_header Cache-Control 'public, max-age=31536000, immutable';
   }

If you wanted this to also apply to agreggates as well as the individual AdvAgg optimized files, just removed the optimized from the location line.

Serving Compressed Assets.

On Apache, AdvaAgg handles this pretty well. On other servers, it doesn't however, if you've already configured your server to serve compressed assets from Drupal core, likely it'll just work. On the other hand, many Nginx default configurations may not be setup to serve static compressed assets.

Brotli

At this point in time, serving Brotli assets will still require you to build your Nginx server from source, with the Nginx Brotli module - doable but beyond the scope of this manual. Once you have that installed, configuring your vhost/server settings is very easy, just add the following:

   location ~ ^/sites/.*/files/(css|js) {
     brotli_static on;
   }

Gzip

Serving Gzip assets also requires a seperate module to be enabled it is part of the main nginx code and there are distributions with it - for example on Ubuntu use apt-get install nginx-extras to install a prebuilt version, otherwise you can build your own custom version. See more details about the Nginx GZip Module Configuring your server setting is equally easy and almost identical to the Brotli configuration:

   location ~ ^/sites/.*/files/(css|js) {
     gzip_static on;
   }

If you want to serve either Gzip or Brotli depending on the user's browser just use both declarations: vhost/server settings is very easy, just add the following:

   location ~ ^/sites/.*/files/(css|js) {
     brotli_static on;
     gzip_static on;
   }

TIPS & TRICKS

JavaScript Bookmarklet

You can use this JS code as a bookmarklet for toggling the AdvAgg URL parameter. See http://en.wikipedia.org/wiki/Bookmarklet for more details.

    javascript:(function(){
      var loc = document.location.href,
          qs = document.location.search,
          regex_off = /\&?advagg=-1/,
          goto = loc;
      if(qs.match(regex_off)) {
        goto = loc.replace(regex_off, '');
      } else {
        qs = qs ? qs + '&advagg=-1' : '?advagg=-1';
        goto = document.location.pathname + qs;
      }
      window.location = goto;
    })();

HOW TO GET A HIGH PAGESPEED SCORE

Go to admin/config/development/performance/advagg - check "Combine CSS files by using media queries"

Ensure AdvAgg Modifier is enabled and go to admin/config/development/performance/advagg/mod - Under "Move JS to the footer" Select "All" - set "Enable preprocess on all JS/CSS" - set "Move JavaScript added by drupal_add_html_head() into drupal_add_js()" - Enable every checkbox under "Optimize JavaScript/CSS Ordering"

Ensure AdvAgg Minify JS is enabled and go to admin/config/development/performance/advagg/js-minify - Select JSMin if available; otherwise select JSMin+

ADVANCED AGGREGATES CDN

OVERVIEW

Note: This module may have conflicts, but only with other CDN type modules.

Load CSS or JavaScript libraries from a public CDN; currently only supports jQuery and jQuery UI with either Google's or Microsoft's CDN. Note the theme for the jQuery UI CSS that Drupal core uses is not available from either CDN. There is a similar one, smoothness, available which has only very minor differences.

CONFIGURATION

Located at admin/config/development/performance/advagg/cdn.

jQuery

jQuery UI

ADVANCED AGGREGATES CSS/JS VALIDATOR

OVERVIEW

Validate CSS and or JS files in your site through a few different validators.

CSSLint

Use the CSSLint JavaScript and the Drupal 8 core .csslintrc settings to lint the selected file(s) from your site.

W3.org CSS VALIDATOR

Warning: this has privacy implications. Specifically this sends your CSS to the W3 servers.

Use the W3.org CSS Validator to lint the selected file(s) from your site.

JSHint

Use the JSHint JavaScript to lint the files on your site.

ADVANCED AGGREGATES EXTERNAL MINIFIER

OVERVIEW

Warning: depending on permissions this presents a security risk due to using administrator configurable command line calls.

Note: May conflict with AdvAgg Minify CSS and or AdvAgg Minify JS depending on configuration. Don't use 2 minifiers on one asset type.

Minify CSS or JS through an otherwise unsupported method, with a configurable command line. This may not work on all servers depending on security settings.

CONFIGURATION

### CSS

### JavaScript

ADVANCED AGGREGATES MINIFY CSS

OVERVIEW

Minify CSS files using a 3rd party minifier; currently supports YUI (included) or the Core cleaning algorithm. YUI will lead to much smaller files sizes and is the recommended option - basically, if you aren't using it, you probably will get better performance without this sub-module enabled. The YUI Compressor included with Advanced Aggregates is slightly different from that found on GitHub (as of last check, one patch had not been applied to the GitHub version).

CONFIGURATION

Located at admin/config/development/performance/advagg/css-minify

ADVANCED AGGREGATES MINIFY JAVASCRIPT

OVERVIEW

Minify JavaScript files using a 3rd party minifier. AdvAgg includes a few and supports one faster compiled PHP extension. The options are:

CONFIGURATION

Located at admin/config/development/performance/advagg/css-minify

JSMIN PHP EXTENSION

The AdvAgg Minify JavaScript module can take advantage of jsmin.c if it is available and selected as minifier. In that case, JavaScript parsing and minimizing will be done in C instead of PHP dramatically speeding up the process. The JsMin extension can be found at GitHub. There are instructions on installing and compiling it there. Note that if you are using PHP 7.x you'll need to use the feature/php7 branch rather than the master branch.

ADVANCED AGGREGATES MODIFIER

OVERVIEW

Depending on tweaks applied this module may cause compatibility issues with other modules.

Includes additional tweaks that may not work for all sites such as: - Force preprocessing for all CSS/JS. - Add defer tag to all JS. - Defer CSS loading using rel=preload and JavaScript Polyfill. - Add async tag to all or only local JavaScript. Some of these may significantly increase performance depending on your individual site. However, they include possibly dangerous and minimally tested options so use care and read warnings on each option if there are any.

CONFIGURATION

Located at admin/config/development/performance/advagg/mod.

JS

CSS

ADVANCED AGGREGATES OLD IE COMPATIBILITY ENHANCER

OVERVIEW

This module may have conflicts with other modules if it is enabled.

Includes additional functionality to improve Drupal compatibility with old versions of Internet Explorer (6-9). No currently known compatibility issues however due to method required to override core on this it is easily possible that there are other modules that do conflict.

This module prevents CSS aggregates from being produced with more than 4095 (or a configured value) selectors as old Internet Explorer versions do not handle more than 4095 selectors in an individual file.

CONFIGURATION

Located at admin/config/development/performance/advagg/old_ie_compatibility.