2
votes

Google Tag Manager (GTM) minifies all tags and snippets and serves them minified. Which is good.

But the javascript that loads the tags itself is not minimized.

For example: https://www.googletagmanager.com/gtm.js?id=GTM-WPGCQNW

// Copyright 2012 Google Inc. All rights reserved.
(function(w,g){w[g]=w[g]||{};w[g].e=function(s){return eval(s);};})(window,'google_tag_manager');(function(){

var data = {
"resource": {
  "version":"137",
  "macros":[{
      "function":"__jsm",
      "vtp_javascript":["template","(function(){var a=new Date(document.querySelector('meta[name\\x3d\"article_date_original\"]').content);return a.toISOString()})();"]
...

Here you see that the total javascript is not minified, but the contents of each line is minified.

My question is, might there be an answer to it: how can I link to a minified version? Does Google offer this as well?

1

1 Answers

4
votes

Google does not offer this.

Since the GTM file does not need a backchannel (it is pure Javascript) you could download it to your server, minify it there and link the resulting file in your website (by "download" I mean something like a proxy that downloads and minifies on the fly, or in prescribed intervals, in order to alway receive the lastest version of the GTM file).

It is of course possible that further minification will break the file. Also since the file is delivered gzipped to the browser, and a bunch of spaces compress pretty well, it is unlikely that further minification will have a big effect (you would need to see that your own server zips the file again before it is delivered to your site, or you just make things worse).

I do not think this is actually a worthwhile idea, but it is basically the only way to minify the file beyond what Google does for you.