DADI has rebranded to Edge. Find out more.

DADI Web Feature: Post Processors

In the next release of DADI Web, version 5.0, we’ll be adding a small but powerful new feature we’re calling ‘post processors’.

In the next release of DADI Web, version 5.0, we’ll be adding a small but powerful new feature we’re calling ‘post processors’ (borrowed from a little known Wordpress feature).

For example you may want to enforce a style-guide amongst several editors, such as enforcing typographers quotes or converting units of measurement automatically for different audiences.

One use we’ve been finding it particularly useful for is minifying the HTML output of a website.

🔗Example

This process is very straightforward thanks to a NPM package called html-minifier, so let’s go ahead and install that in our project:

npm install html-minifier

Next we will create a file event in the new workspaces folder processors.

workspace/processors/minify-html.js

const minify = require('html-minifier').minify

module.exports = (data, output) => {
  return minify(output, {
    collapseWhitespace: true,
    minifyCSS: true,
    minifyJS: true,
    removeRedundantAttributes: true,
    useShortDoctype: true,
    removeComments: true
  })
}

We’re using the options here provided by the html-minifier package we installed. Of course your needs may differ so customize for your requirements.

Next we need to update Web’s configiration file (for example config/config.development.json) to load the new processor for every request:

"globalPostProcessors": [
   "minify-html"
]

And that’s it! You should now see minified HTML sent to your browser.

If you need to disable (or enable) on a page-by-page basis you can customize the options in your page.json files:

To disable all global post processors:

{
  "settings": {
     "postProcessors": false
  }
}

To enable only a specific one:

{
  "settings": {
    "postProcessors": ["remove-swear-words"]
  }
}

🔗Conclusion

You can read more of the technical details in the pull request for this feature.

We will be talking more about Web 5.0 in the coming weeks so please stay tuned or let us know if there are any features you would like to see. And of course, we’ll let you know when it’s released via Twitter.

Related articles

More updates articles
Mail icon

Like what you are reading? Want to earn tokens by becoming an Edge Node? Save money on your hosting services? Build amazing digital products on top of Edge services? Join our mailing list.

To hear about our news, events, products and services, subscribe now. You can also indicate which services you are interested in, which we use for research and to inform the content that we send.

* You can unsubscribe at any time by emailing us at data@edge.network or by clicking on the unsubscribe link which can be found in our emails to you. Read our Privacy Policy.
Winner Best Edge Computing Platform Technology & Innovation Awards
Presented by Juniper Research