UNPKG

1.16 kBMarkdownView Raw
1
2Output Filters
3==============
4
5Output filters allow the rendered output to undergo some post processing before being sent to the client. One of our use cases has been to perform HTML optimizations on the content. This includes things like removing optional closing elements and normalizing boolean attributes.
6
7Filters are defined in ``filters/output`` with their corresponding tests living in the ``tests/server/filters/output`` folder.
8
9Defining an Output Filter
10-------------------------
11
12Output filters export a function that accepts up to four parameters. The parameters are a string containing the rendered content, the content type being returned, the request object and the shunter config. It should return the modified content, or undefined if it wants to pass the content through unmodified.
13
14In the following example we'll process responses with a ``text/plain`` content type and replace all instances of shunter with Shunter.
15
16```js
17module.exports = function(content, contentType, request, config) {
18 if (contentType === 'text/plain') {
19 return content.replace(/shunter/ig, 'Shunter');
20 }
21}
22```
23
24---
25
26Related:
27
28- [Full API Documentation](index.md)