Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

Precompression on aem/dispatcher with brotli

basti1984
Level 1
Level 1

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?

4 Replies
smacdonald2008
Level 10
Level 10

I have never heard of this use case. If other community members have, please comment on this thread.

basti1984
Level 1
Level 1

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

Alex_Popov1
Level 4
Level 4

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

Jörg_Hoh
Employee
Employee

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