Some of the biggest tech companies provide the most bloated code

in technology •  21 days ago

    In developer circles, a sure way to get a bit more respect is to work for one of the biggest tech companies.

    We are talking FAG/FAANG companies (Facebook, Apple, Google, and to a less extent, Amazon, Netflix). It also used to include Oracle and IBM in there.

    But these companies hire truly massive numbers of developers, and they are not all PHD level galaxy brains.

    They are often extremely talented, they have to be smart to get hired (or aqui-hired), but they answer to their bosses, colleagues, and shareholders, not you and me.

    Hence there are a lot of things they could do to help us that they will not if the benefit to the end user (or humanity) would diminish the benefit to the company stock price or data-acquisition.

    Take their online services that are bloating so many websites out there:

    "Free" Tools

    Screenshot by Dropbox Capture.png

    Not only do they often add to page load times unnecessarily, but very often none of it is set to cache, or even be always delivered centrally many hops away when part of a plugin that is served locally.

    The problem is severalfold when you are essentially providing data in exchange for "free services", such as the horrible Google Analytics 4.

    I have written analytics services, I understand my own limitations in the domain, but even I know that collection of the data shouldn't impinge on the experience of the site they are measuring.

    If the human beings coming to your website are put off by the tools measuring the traffic to the website, the cure is worse than the disease!

    What can you do about it?

    Google often points out their own scripts as a villain in their own PageSpeed Insights!

    Many of the solutions are against the terms of service, and therefore you must be very very aware of the downsides, if caught.

    For WordPress users there is a tool called CAOS which is a WordPress plugin that will host your Google Analytics code locally.

    CAOS plugin is easy to use and completely replaces the provided script, so if you've already added Google Analytics to your site, you can remove it.

    Activate just like any other WP plugin, then in Plugins, Installed Plugins, click on "Settings" in the CAOS listing.

    Enter your Google Analytics tracking ID and set the "Tracking Code" to "Asynchronous" then "Save Changes and Update".

    You are now running the script locally, saving DNS lookups and render-blocking loading.

    But wait, there's more!

    Shrinking the Bloat

    Using the "Regenerate Aliases" feature you can tell CAOS to get a fresh JavaScript file.

    Your Google Analytics tracking settings influence the size of this script, and the default racking are probably more than you need (especially if you are not, say, an ecommerce site) so you can turn off some of these tracking events and reduce the size of the tracking script, shortening load times and reducing unused bloat.

    I can't tell you which are useful to your particular situation, just remember the more tracking events you have, the larger the script that will be generated.

    More?

    This might be all you need, especially if not trying to beat PageSpeed scores and care more about user experience, but if you do need more performance you might need some code.

    Specifically, rather than Async, which is an improvement, you can use defer and because it is going to need to connect to Google's servers anyway, add this to your header <link rel='preconnect' href='//www.google-analytics.com' />.

    Finally, and this breaks the automatic update of the JS, you can manually compress the code using an online JavaScript minifiying service.

    Conclusion

    There is no reason why so many websites out there are being delayed in loading because of this JavaScript. All I can think is these people who are much smarter than me just have no incentive.

    Not enough of an incentive, anyway.

      Authors get paid when people like you upvote their post.
      If you enjoyed what you read here, create your account today and start earning FREE VOILK!