Skip to content

Commit

Permalink
rename
Browse files Browse the repository at this point in the history
  • Loading branch information
tristanlee85 committed Jul 8, 2024
1 parent b6da9c0 commit c574def
Show file tree
Hide file tree
Showing 11 changed files with 23 additions and 40 deletions.
38 changes: 0 additions & 38 deletions examples/polyfill.io-replace/edge-functions/main.js

This file was deleted.

File renamed without changes.
File renamed without changes.
21 changes: 21 additions & 0 deletions examples/polyfill_io-replace/edge-functions/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
export async function handleHttpRequest(request, context) {
const baseReplacementUrl = 'https://cdnjs.cloudflare.com';
const srcPrefixes = [
'https://polyfill.io',
'http://polyfill.io',
'//polyfill.io',
];

const transformerDefinitions = srcPrefixes.map((prefix) => ({
selector: `script[src^="${prefix}"]`,
element: async (el) => {
const src = el.get_attribute('src');
el.set_attribute('src', src.replace(prefix, baseReplacementUrl));
},
}));

// Serve the origin response, transforming the HTML content to replace the polyfill.io script tag(s)
return fetch(request.url, { edgio: { origin: 'my-origin' } }).then(
(response) => HtmlTransformer.stream(transformerDefinitions, response)
);
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "edgio-polyfill.io-replace-example",
"name": "edgio-polyfill_io-replace-example",
"version": "1.0.0",
"description": "",
"scripts": {
Expand All @@ -17,4 +17,4 @@
"@edgio/prefetch": "^7.12.5"
},
"repository": "[email protected]:edgio-docs/edgio-polyfill.io-replace-example.git"
}
}
File renamed without changes.

0 comments on commit c574def

Please sign in to comment.