Netlify Connect can make your external data feel like it’s part of your Netlify site, even though it’s living elsewhere.
Imagine you have a product catalog in a headless CMS or a database, and you want to display that information directly on your Netlify-powered e-commerce site. Normally, you’d have to fetch this data at runtime using API calls from your frontend, which can add latency and complexity. Netlify Connect bridges this gap by synchronizing that external data into Netlify’s Edge Functions, allowing your site to access it as if it were part of your static build.
Let’s see it in action. Suppose we have a simple product list stored in a Contentful space.
[
{
"id": "prod_123",
"name": "Awesome Gadget",
"price": 99.99,
"description": "This gadget does amazing things."
},
{
"id": "prod_456",
"name": "Super Widget",
"price": 49.50,
"description": "A widget that's super."
}
]
With Netlify Connect configured, we can write a Next.js page that accesses this data directly.
// pages/products.js
import React from 'react';
function ProductsPage({ products }) {
return (
<div>
<h1>Our Products</h1>
<ul>
{products.map((product) => (
<li key={product.id}>
<h2>{product.name}</h2>
<p>${product.price.toFixed(2)}</p>
<p>{product.description}</p>
</li>
))}
</ul>
</div>
);
}
export async function getStaticProps() {
// Netlify Connect makes this data available locally,
// as if it were fetched from a local file.
const products = await import('../data/products.json'); // This import is simulated by Netlify Connect
return {
props: {
products: products.default, // Assuming default export for JSON
},
};
}
export default ProductsPage;
Here’s how Netlify Connect makes this possible. It acts as a local filesystem abstraction. When you configure Netlify Connect in your netlify.toml, you point it to your external data source. Netlify Connect then uses an Edge Function to poll this source, pull the data, and make it available to your build process and at runtime as if it were a file within your repository. During the build, your static generation functions (like getStaticProps in Next.js) can import these "files," and at runtime, your Edge Functions can access them.
The core problem Netlify Connect solves is the disconnect between your static-generated site and dynamic, external data. Without it, you’d typically fetch this data on every request to your live site, increasing latency and the load on your external data source. By syncing the data into Netlify’s Edge network, it’s delivered much faster, often from edge locations close to your users.
To set this up, you’ll modify your netlify.toml file. For Contentful, it might look something like this:
[functions]
directory = "netlify/functions"
[[plugins]]
package = "@netlify/plugin-netlify-connect"
[plugin.netlify-connect]
# Example for Contentful
contentful = { space = "YOUR_SPACE_ID", environment = "master", access_token = "YOUR_ACCESS_TOKEN" }
Here, the plugin.netlify-connect section tells the plugin where your data lives. The plugin then configures an Edge Function that fetches this data. The magic happens because Netlify Connect intercepts import statements for paths that it knows are mapped to external data sources. For example, if you configure a local_path that maps to a remote source, import '../data/products.json' will resolve to the data fetched from your remote source, not a file in your repo.
The mechanism by which Netlify Connect makes remote data appear local is through a virtual filesystem exposed to Edge Functions and the build process. When your build command runs, or an Edge Function is invoked, Netlify Connect intercepts file system operations for configured paths. Instead of reading from disk, it queries its synchronized cache of the external data. This cache is periodically updated by a background process within Netlify’s infrastructure, ensuring your site reflects reasonably up-to-date information without requiring a full site rebuild for every data change.
The surprising part is how seamlessly this integration works with existing tooling. You don’t need to rewrite your data fetching logic to use a special SDK. If your external data source supports a RESTful API (like many CMSs or databases), Netlify Connect can often adapt to it, making it feel like a simple file import or a direct API call from an Edge Function. This abstraction layer means your frontend code remains largely unaware of the data’s origin, treating it as a local asset.
The next hurdle you’ll likely encounter is managing data freshness and conflict resolution when multiple sources or updates occur concurrently.