Can I use Netlify Functions to serve a 3rd party script?

Is it possible to load a 3rd party script using Netlify Functions? I’m trying to make my site faster and a 3rd party script from makes my site up to 1021 ms slower. (I already minify CSS etc.)

If the url to my script is, what function could I write to make it available on my website faster?

(The script is essential to basic website functions so I can’t delete it, I’ve already tried async, defer, prefetch etc.)

Hi, @askthings. Is the issue that the loading of the URL from is slow? If the script permissions allow for it, you might just copy that file into your local repo and host it directly from your site’s domain name. This might give you better performance but, again, I don’t know if the permissions of the script allow for this or not.

The script is essentially just a text file which contains javascript. This file needs to be sent to the end users web browser to it can be executed by the browser itself. It doesn’t matter where the javascript is hosted as long as the correct javascript is loaded. (There can be Cross-Origin Resource Sharing issue if the domain name where the script is loaded doesn’t match the site’s domain name but this doesn’t appear to be an issue with this script.)

Obviously, if the script is being loaded from some domain that Netlify doesn’t control, the speed of loading that script isn’t something that Netlify can control. However, if you move the script to Netlify and it is still loading slowly, we are happy to research why.

Regarding making a Function to do this, Functions are code that run in a system outside of the local users browser. Functions are used for many purposes, such as providing an API for a site to use. However, you don’t need to write functions if all you are doing is sending a static javascript file to an end user.

If you simply include the javascript file as a file in the publish directory during the site deploy, the file will be available at that relative path once the deploy is completed. In other words, you don’t need to write a function to serve a javascript file.

If there are other questions, please let us know. Also, please consider sharing the actual URLs with us here. With the actual URL, we can troubleshoot the issue directly and provide much better information because we answering specifically about directly observed behavior as opposed to making best guesses about hypotheticals.

I decided to self-host, thanks!