---
title: "Comment by Adi on \"How to Lazy Load Images with an Edge Worker\" | Hashnode"
description: "Hello, I want to change the blogger permalink /p/test.html to /test-page/ and also canonical link and other links. but still can&#39;t rewrite the canonical and"
url: "https://hashnode.com/posts/how-to-lazy-load-images-with-an-edge-worker/60fa225862e20b58c1c9156f/comment/625693e0b32ddd968bbed2c7"
---

[Discussion](https://hashnode.com/posts/how-to-lazy-load-images-with-an-edge-worker/60fa225862e20b58c1c9156f)

Comment [How to Lazy Load Images with an Edge Worker](https://hashnode.com/posts/how-to-lazy-load-images-with-an-edge-worker/60fa225862e20b58c1c9156f)

[Adi](https://hashnode.com/@adicom)

[Apr 13, 2022](https://hashnode.com/posts/how-to-lazy-load-images-with-an-edge-worker/60fa225862e20b58c1c9156f/comment/625693e0b32ddd968bbed2c7)

Hello, I want to change the blogger permalink /p/test.html to /test-page/ and also canonical link and other links. but still can't rewrite the canonical and other links.

first code, with route settings like this: `www.domain.com/test-page*`

```
addEventListener("fetch", event => {
    return event.respondWith(fetch("domain.com/p/test.html"))
})
```

the second code, and the route settings are like this `*.domain.com/test-page*`

```
const OLD_URL = "domain.com/p/test.html";
const NEW_URL = "domain.com/test-page";
async function handleRequest(req) {
  const res = await fetch(req)
  return rewriter.transform(res)
}
class AttributeRewriter {
  constructor(attributeName) {
    this.attributeName = attributeName
  }
  element(element) {
    const attribute = element.getAttribute(this.attributeName)
    if (attribute) {
      element.setAttribute(
        this.attributeName,
        attribute.replace(OLD_URL, NEW_URL)
      )
    }
  }
}
const rewriter = new HTMLRewriter()
  .on("link", new AttributeRewriter("href"))
  .on("meta", new AttributeRewriter("content"))
addEventListener("fetch", event => {
    let url = event.request.url
  event.respondWith(handleRequest(url)
  .catch(err => new Response(err.toString(),{status:500})))
})
```

[Kennedy Rose](https://hashnode.com/@kennedyrose)

[Apr 13, 2022](https://hashnode.com/posts/how-to-lazy-load-images-with-an-edge-worker/60fa225862e20b58c1c9156f/comment/625693e0b32ddd968bbed2c7#reply-6256cdb9d448c6c43fbf1512)

I'm not entirely sure. I don't think I've ever tried to change canonical links with Cloudflare workers. They have lots of [examples](https://developers.cloudflare.com/workers/examples/) in their docs though. You should be able to modify one of those examples to suit your needs.

[Adi](https://hashnode.com/@adicom)

[Apr 13, 2022](https://hashnode.com/posts/how-to-lazy-load-images-with-an-edge-worker/60fa225862e20b58c1c9156f/comment/625693e0b32ddd968bbed2c7#reply-625701cfd448c6c43fbf1a55)

when I just run the code rewrite it works rewrite the canonical link with route `www.domain.com/p/test.html`. I can't seem to run concurrently, is there maybe something wrong with my route settings? I've also changed my codes and still the same still can't rewrite the canonical link.
