This middleware looks for a _filter query string in a request. If it is present and the response has a content-type of text/html only the element with the given id will be returned. If the id is not found in the response an empty div element will be returned.
To illustrate this behaviour lets assume that a backend server generates this response:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Test document</title> </head> <body> <h1 id="header">Test document</h1> <div id="body"> <p>Welcome to our little test</p> </div> </body> </html>
If a browsers requests this document using a request for http://www.example.com/ the document will be returned untouched.
Lets suppose that AJAX capability is being added to your site and you need to inject the header from this document. Fetching the whole document from the server and extracting the header element fmor the document can be expensive. This is very noticable in older versions of IE which are very slow in building a DOM for the requested data and extracting the right bits form it. Instead of fetching the full document and extracting the right you can ask repoze.slicer to do the filtering by making a request for http://www.example.com/?_filter=header. The returned data will then look like this:
<h1 id="header">Test document</h1>