Created
April 5, 2012 18:32
-
-
Save paxtonhare/2313109 to your computer and use it in GitHub Desktop.
GZip compression in the browser using MarkLogic 5.0-3 and greater
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if (fn:contains(xdmp:get-request-header("Accept-Encoding", ""), "gzip")) then | |
(: do your gzipping here :) | |
else | |
(: don't gzip :) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
xdmp:add-response-header("Content-Encoding", "gzip") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let $content := | |
<html> | |
<head> | |
<title>Hello gzip compression</title> | |
</head> | |
<body> | |
<h1>gzip compression, FTW!</h1> | |
</body> | |
</html> | |
return | |
(: make sure the browser can handle gzip compression :) | |
if (fn:contains(xdmp:get-request-header("Accept-Encoding", ""), "gzip")) then | |
( | |
xdmp:add-response-header("Content-Encoding", "gzip"), | |
(: make sure $content is valid. xdmp:zip expects a node() :) | |
if ( fn:exists($content) ) then | |
xdmp:gzip($content) | |
else | |
$content | |
) | |
else | |
$content |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment