Highlighted

Precompression on aem/dispatcher with brotli

basti1984

24-10-2017

Hello everybody,

anybody tried to precompress the content on the dispatcher?

We want to use brotli in our environment and i find some solutions, but no solution i've found used it in/with aem.

We can try to use something like this on the dispatcher:

stalking.sh

#!/bin/sh

while :

do

  find /path/to/content/ -type f | entr -d ~/path/to/compressscript.sh

done

compressscript.sh

#!/bin/sh

for x in 'find /path/to/content/ -type f \( -name '*.html' -o -name '*.js' -o -name '*.css' -o -name '*.xml' -o -name '*.svg' \)

do

     bro --input ${x} --output ${x}.br

done

What do you think?

Replies

Highlighted

basti1984

06-11-2017

I imagined this as follows:

We could write a while-loop-script and runs it on the dispatcher:

stalking.sh:

#!/bin/bash

while; do
     find /hl/aem/apache/dispatcher-cache -type f | entr -d /hl/scripts/compression.sh
done

"entr" runs following script if a file is changed:

compression.sh

#!/bin/bash

for i in $(find ./ -type -f \( -name '*.html' -o -name '*.js' -o -name '*.css' -o -name '*.xml' -o -name '*.jpg' \) ); do

     bro --input ${i} --output ${i}.br

done

After that, we should add following lines to the apache-config:

<Files *.jpeg.br>

AddType "image/jpeg" .br

AddEncoding br .br

</Files>

<Files *.jpg.br>

AddType "image/jpg" .br

AddEncoding br .br

</Files>

<Files *.html.br>

AddType "application/hml" .br

AddEncoding br .br

</Files>

<Files *.xml.br>

AddType "application/xml" .br

AddEncoding br .br

</Files>

<Files *.js.br>

AddType "text/javascript" .br

AddEncoding br .br

</Files>

<Files *.css.br>

AddType "text/css" .br

AddEncoding br .br

</Files>

RewriteEngine On

RewriteCond %{HTTP:Accept-Encoding} br

RewriteCond %{REQUEST_FILENAME} .br -f

RewriteRule ^(.*)$ $1.br [L]

Thus we save compression time and computing power on the server.

Now we facing one problem: "What happens if a File is not cached on the dispatcher?"

Should we run the scripts on the publish-server too?

Or is it even enough to run the scripts only on the publish servers?

I'll test this in the near future in our test environment and i'll report my results.

thanks for reading

Highlighted

Alex_Popov1

21-01-2019

Hi,

Does anyone successfully configured brotli on apache/dispacher?

P.S.: I see that it's possible to enable on akamai (https://developer.akamai.com/blog/2017/11/17/how-automatically-optimize-size-your-critical-page-reso...).

But, it's still interesting to hear about experiences how enable it on apache side.

Thanks,

Alex

Highlighted

Jörg_Hoh

Employee

21-01-2019

Can you elaborate a bit on the usecase? Do you want to compress the files in the dispatcher cache? IIRC the dispatcher cannot make use of these, but on delivery the httpd module "mod_deflate" performs this task.

Jörg