What is Serverless Scripting?
StackPath's Serverless Scripting is a serverless computing platform that allows you to upload JavaScript scripts and have them automatically deployed within seconds to every StackPath datacenter worldwide. There, the scripts can interact with every request that comes into your site (or just the requests you define) and do things like modify the request or response bodies, make decisions based on the request headers or a number of additional StackPath headers, make additional fetch queries, or even respond to the request directly without having to send it to your origin.
Why use Serverless Scripting?
Serverless computing allows developers to focus on what's important - coding their application. Once the code is ready, it can be deployed to a serverless environment without the need for the developer to worry about where it's being deployed, provisioning servers or containers, creating failover or scaling plans, etc. StackPath Serverless Scripting takes the traditional serverless concept a step further by allowing developers to deploy to the edge, in data centers all over the world, with one button (or API call) in a matter of seconds. Positioning JavaScript code at the edge puts it close to end-users, allowing developers to apply logic to each and every request they get and return responses or modify requests right there by the user before the requests even go back to the origin server. Such a setup means developers get a simple and easy way to deploy highly-distributed, highly-performant, and highly-scalable global applications.
How does it work?
Serverless scripts are executed in the StackPath data center closest to a given end-user. When a user's request comes in, we execute your JavaScript code in an individual, isolated sandbox environment built on StackPath's custom implementation of the V8 JavaScript Engine. V8 is an open-source JavaScript engine created by Google and used by the Chrome browser as well as many other well-known pieces of software. Because V8 is open-source and widely used, it is highly secure (Google itself is very motivated to keep it that way) and StackPath has added even more security mechanisms to keep your code secure and completely separate from anyone else's. Using V8 also allows your code to be started extremely quickly, whether it's being run for the first time or the thousandth.
When a user request comes into a StackPath data center and your code is executed in the V8 engine, your code is executing before StackPath's CDN cache or WAF services. This ordering means you have complete control over incoming requests before StackPath responds to them, and can manipulate (or block) requests before StackPath responds or they get to your origin server.
What is Serverless Scripting not?
Serverless Scripting gives developers incredible capability and flexibility to easily deploy serverless applications around the world, but there are still a few things it is not. To be clear and transparent about what those are, we thought we should list those here:
- Serverless Scripting is not a replacement for or alternative to the StackPath CDN.
- Serverless Scripting does not yet support languages other than JavaScript (though support for additional language support is coming), or deployment concepts other than serverless computing, e.g. containers or VMs.
- Serverless scripts live and die per request; the code is not continuously running in the background.
What's Next?
To learn how to upload your first Serverless script, please view our Getting Started with Serverless Scripting article.