Skip to content

Other sites

CSS, SCSS and JavaScript snippets can load on any other website, built with WordPress or not, through one script tag. The snippets stay on your WordPress site, which serves them to the other site; PHP snippets run only on your site.

Add a site

A public key decides which external site a script tag serves and which addresses may use it. Keys are created in the workspace’s Settings, in the Public keys section:

  • New key for: sleek-byte/site.
  • Item id (optional): the external site’s id, the name its snippets use for it, such as shop. Left empty, the key serves every external site, and the script tag names the one it loads.
  • Name: what the key is called in the list.
  • Allowed origins: the addresses the site is served at, separated by commas: an origin such as https://shop.example.com, a domain such as example.com for it over HTTP and HTTPS, *.example.com for its subdomains, or * for any site.

Saving creates the key, a pk_ followed by forty characters, and shows it under Created key. Each key in use is listed with the site it serves and the addresses it allows; its Revoke switch, saved, stops it everywhere. A new key for the same item id serves the same snippets, so a key can be replaced without editing them.

Place the script

Put the script tag on the other site’s pages, in their <head> or anywhere in their body, with your site’s address and the key:

HTML
<script
  src="https://your-site.com/wp-json/sleek-byte/v1/external?sleek_key=pk_..."
  async
></script>

On a site with plain permalinks the address is https://your-site.com/?rest_route=/sleek-byte/v1/external&sleek_key=pk_.... A key for every external site names the one it loads with &site=shop; a key for one site refuses another. Without site, such a key loads only the snippets for every site.

Assign a snippet

A snippet’s snippet.json assigns it to external sites under external:

JSON
{
  "external": {
    "sites": ["shop", "blog"],
    "include": ["/products/*", "/"],
    "exclude": ["/products/archive/*"]
  }
}
Key Type Meaning
sites string or array The item ids of the external sites the snippet loads on, or * for every one. Omitted, it loads on none.
include string or array The URL path patterns of the pages it loads on. Omitted or empty, it loads on every page of those sites.
exclude string or array The URL path patterns of the pages it never loads on, even when an include pattern matches them as well.

A pattern is a page’s path, without its address or query string, such as /products/shoes; * stands for any run of characters, slashes included, so /products/* matches every page below /products/ and / only the home page. The loader compares the patterns with each page’s path in the visitor’s browser, so they need nothing from your site.

The snippet’s CSS and JavaScript files load on those pages in the order of their paths, the stylesheets at once and the scripts once the page has been parsed, as footer scripts run on your site. A JavaScript file whose options set module loads as a module. An SCSS file is compiled when it is saved and arrives as CSS; a partial, whose name starts with an underscore, is only imported.

Only enabled, environments and schedule from whether it runs apply on other sites, checked by your site as it serves them. Contexts, conditions, hooks, dependencies and external assets read your site’s own pages and do not apply there, and PHP files are never served. A snippet with an empty context, "context": [], loads on no page of your own site, only on the external sites it names.

Which sites may load it

Only the addresses the key allows get the script and the snippets’ files, which your site checks on every request by the page’s address. A page that sends no address, such as one with Referrer-Policy: no-referrer, can load only the snippets of a key that allows *. A revoked key, a changed assignment or a newly saved file shows within five minutes, when visitors’ browsers ask for the script again.

Caching

The script is cached by each visitor’s browser for five minutes. Each file’s address carries its version, the time it was last saved, so browsers keep a file for a year and fetch it again only once it changes. Every answer is private to the visitor’s browser: no shared cache keeps it for another site.

Limits

Each visitor’s address may make 600 requests a minute with one key, the script and each file counting once, and all visitors together 60,000; a request past either limit is refused with HTTP 429 until the minute ends.

Stay in the Loop!  

Be the first to hear about new updates, special offers, and helpful tips, delivered straight to your inbox.

We respect your inbox (and your privacy). Read our privacy policy.