41. General

ShimmerCat comes with a built-in JS agent, which is an async JS script that can be inserted in HTML contents. The purpose of the script is to collect performance metrics to show in the customer’s dashboards, and to assess the efficacy of acceleration measures.

42. How the JS snippet is inserted

When configured, the snippet is inserted by injecting the following fragment in the HTML code:

<script type="text/javascript" src="/.well-known/shimmercat/ovfs/js/agent.js" async></script>

The exact place where the <script> tag is inserted in the HTML stream is configured in each HTML-transacting view, as discussed in the next section.

43. Inserting the script

To insert the script, a fragment like the following one needs to be added to views that have “content-disposition: replace” and that traffic HTML:

    content-disposition: replace
       - / -> /fastcgi_0.php
       - "</body>\\n"

New here is the array under sc-snippet-after. This array should contain HTML fragments close to the end of the main HTML document; ShimmerCat will insert the snippet right after the first of the given fragments which is found in the HTML document.

By carefully selecting the view(s) and the snippets in the sc-snippet-after array, you can control when and where the script tag is inserted.

44. Performance

ShimmerCat uses literal string matching and the Aho-Corasick algorithm to find matches for the array of literals under sc-snippet-after. The Aho-Corasick algorithm creates a deterministic automaton that can match all the patterns simulateneously in a very efficient way. Furthermore, ShimmerCat compiles this automaton straight to machine code and stores a cached dynamic link object under t-cache in the scratch folder.