How we built the Fastest ChatGPT Website Chatbot
Tags: openai, chatgpt, webdev, tutorial
Published: 2023-04-27 04:30:44

A ChatGPT-based website chatbot can _dramatically decrease your website's performance_ if it's not correctly implemented. Today we were able to further optimised [our ChatGPT chatbot](https://ainiro.io) and make it 20x faster than what we started out with as we cloned AISTA's technology. In totalt we have now reduced the initial page load time from more than 1,000kB to less than 48kB. This is a 20x improvement in load time, significantly impacting SEO and usability.

In this article I will tell you how, in addition to why this is important, and why you should care. The image below shows a default empty HTML page, with our chatbot embedded. Basically it scores 100% on every single parameter that exists.

![ChatGPT website chatbot performance](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2tw1iert9hnuau77h7gy.jpeg)

## The importance of a CDN

A Content Deliver Network (CDN) allows you to serve static resources _a lot_ faster. To understand why, realise that the internet has a lot to do with geography. I live in Cyprus. From Cyprus to Ukraine I have a TCP hop time (latency) of probably 100+ milliseconds. This doesn't sound like much, but when your website is serving 50+ HTTP requests, this becomes an additional load time of 50 x 0.1 seconds, resulting in 5 seconds more time to load.

> If your webpage requires 5 seconds to load, you might as well send a postcard!

We're using a global CDN that caches every single static file locally, reducing latency to ~10 milliseconds. Hint; [CloudFlare](https://cloudflare.com) - USE IT!

## Lazy initialising reCAPTCHA

A chatbot such as ours needs reCAPTCHA support. Without it, any script kid can create a never ending while loop in Postman, and burn through thousands of dollars in your OpenAI API account in a couple of hours. However, reCAPTCHA is terribly implemented. It's a _"blocking library"_, implying the rendering of your webpage will halt while reCAPTCHA is downloaded and initialised. I wrote about [how to defer reCAPTCHA loading in this article](https://ainiro.io/blog/how-we-made-our-chatbot-10x-faster) if interested. However, the idea is that we don't load reCAPTCHA before the chat button is clicked. You can actually see this if you inspect the network tab on this page, for then to click the little blue robot in the bottom/right corner. The idea is to _never_ load anything before you need it!

## Trimming fonts

We're using [IcoFont](https://www.icofont.com/icons) for our chatbots. These are the small icons displayed by default on for instance the chess theme, and/or the [AI search](https://ainiro.io/blog/put-ai-search-on-your-website) button. IcoFont has a really amazing feature, which is that you can _"cherry pick"_ which icons to download. If you download some _"font icon library"_ you will typically get hundreds of icons. These icons will consume bandwidth, and you rarely need more than a handful. The default version of IcoFont for instance requires 0.5 megabytes of download. By cherry picking which icons we want in our set, we were able to reduce the size of our IcoFont library from ~500kB to ~5kB. 0.49 megabytes of bandwidth saved!

## GZIP'ing content

This one we get for free, it's an integrated part of CloudFlare's services, that reduces the size of static content such as JavaScript and CSS by roughly 90 to 95 percent. If you've got heavy JavaScript and CSS files, you want to make sure your content is GZip'ed as it's being served. However, we got this one _"for free"_ because of using CloudFlare's CDN features.

## Zero "Frameworks"

If you're creating a chatbot that's intended to be embedded on a website, then _do not start out by dragging in Bootstrap or jQuery_. The domain problem for a chatbot is easy, you don't need Bootstrap or jQuery. These libraries are hundreds of kilobytes in size, and this becomes a cost for the website you're embedding the chatbot on. Our chatbot exclusively contains _"good old fashioned JavaScript and CSS"_, and no frameworks. If your ChatGPT-based website chatbot downloads jQuery or Bootstrap, you might want to reconsider what chatbot service you're using ...

## Page load time matters

There are literally no parameter that's more important for user experience and SEO than page load time. Google will rank you higher than your competitors if your page is loading faster assuming the rest of the parameters are equal. This implies that if you're _"embedding the coolest ChatGPT-based website chatbot on Earth on your page"_, you might wake up one day and realise you've lost 50% of your organic clicks from Google, and that the average engagement time just dropped by 50%, because people are clicking the back button because they're tired of waiting for your webpage to load.

Some millennials will even watch YouTube videos on 1.5x speed, because they don't have time to watch these at normal speed. Do me a favour please; Copy the URL of this page, and open it in an incognito browser window. Did you notice it loaded in less than 1 second? That took _a lot_ of effort from us, but inevitably over time results in a better user experience, and more _"Google Luv"_ over time.

Before you chose a ChatGPT website chatbot, ask yourself _"what's the cost"_. Well, if you chose us, you now know, 47kB. Most others are in the 1,000+ range here ... 😉

* [Contact us for a quote on our ChatGPT website chatbot](https://ainiro.io/contact-us#demo)
* [Or create your own ChatGPT website chatbot here](https://ainiro.io/blog/how-to-get-chatgpt-on-your-website)

Psst, we're constantly working to further improve our chatbot tech, and I suspect we might be able to squeeze it down to less than 30kB in total over the next weeks - However, even at 48kB, I suspect we're probably the fastest ChatGPT-based Website Chatbot on Earth 😁