# Code highlighting failed because bunny.net CDN

**URL:** https://meta.discourse.org/t/code-highlighting-failed-because-bunny-net-cdn/296333
**Category:** Support
**Tags:** cdn, cors
**Created:** [February 22, 2024, 3:00pm UTC](https://meta.discourse.org/t/code-highlighting-failed-because-bunny-net-cdn/296333 "2024-02-22T15:00:50Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [February 22, 2024, 3:00pm UTC](https://meta.discourse.org/t/code-highlighting-failed-because-bunny-net-cdn/296333/1 "2024-02-22T15:00:50Z")

</div>

Someone compained that code highlighting isn’t working on their site. I’ve replicated the issue on mine. The issue seems to be that the CDN is blocked by CORS policy:

> [@](#):
>
> Access to script at ‘[https://cdn.dashboard.literatecomputing.com/highlight-js/dashboard.literatecomputing.com/8ca560096c2b0ff3f6aa461e5bf6df6ea43921a5.js](https://cdn.dashboard.literatecomputing.com/highlight-js/dashboard.literatecomputing.com/8ca560096c2b0ff3f6aa461e5bf6df6ea43921a5.js)’ from origin ‘[https://dashboard.literatecomputing.com](https://dashboard.literatecomputing.com)’ has been blocked by CORS policy: No ‘Access-Control-Allow-Origin’ header is present on the requested resource.

![image](https://global.discourse-cdn.com/meta/original/4X/0/1/b/01be06c3d76d821322f545c1dbde47318c59771c.png)

I fixed the problem by adding `js` to the “add cors header” setting on the cors page:

 ![image](https://global.discourse-cdn.com/meta/original/4X/d/a/c/dace017404ee4604a6d0f6b8445a7353be53bddb.png)

If enabled, [bunny.net](http://bunny.net) will automatically add CORS headers (Cross-Origin Resource Sharing) to all requests to files with extensions from the list.

This post is to document it in case someone else has an issue with a [bunny.net](http://bunny.net) CDN and to make sure that I understand this.

---

<div class="post-metadata">

### Author: ![itsbhanusharma](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/itsbhanusharma/32/180717_2.png) [@itsbhanusharma](https://meta.discourse.org/u/itsbhanusharma)
#### Post date: [February 25, 2024, 3:06am UTC](https://meta.discourse.org/t/code-highlighting-failed-because-bunny-net-cdn/296333/2 "2024-02-25T03:06:00Z")

</div>

I believe there is (or used to be) a setting in bunny which added js to cors? I (for some reason) have js added to cors for all my [bunny.net](http://bunny.net) resources but I don’t recall adding them myself. Is it a fairly new site?

---

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [February 25, 2024, 7:41am UTC](https://meta.discourse.org/t/code-highlighting-failed-because-bunny-net-cdn/296333/3 "2024-02-25T07:41:23Z")

</div>

The site where they first noticed it has been around a long time (don’t remember when they started using bunny).

I’m not sure if bunny changed or something about the included script did.

---

<div class="post-metadata">

### Author: ![david](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/david/32/157490_2.png) [@david](https://meta.discourse.org/u/david)
#### Post date: [March 8, 2024, 10:49am UTC](https://meta.discourse.org/t/code-highlighting-failed-because-bunny-net-cdn/296333/4 "2024-03-08T10:49:45Z")

</div>

The change which made this noticeable was most likely [DEV: Modernise highlightjs loading (#24197) · discourse/discourse@0878dde · GitHub](https://github.com/discourse/discourse/commit/0878dde2132a34ba2787e702de222bc6dd161895), which switched highlightjs to load via native `import()`, which requires CORS headers when fetching from a CDN.

But even before that change, you likely would have had some issues with things like custom Fonts (which also require CORS headers for cross-origin requests).

In theory, Discourse itself should be adding the CORS header to CDN responses. If it’s not, that probably means your CDN is not setting the CDN hostname (i.e. not the forum hostname) in the `Host` header or the `X-Forwarded-Host` header.

That said, adding the headers via the CDN config likely achieves the same thing 👌

---

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [April 7, 2024, 10:49am UTC](https://meta.discourse.org/t/code-highlighting-failed-because-bunny-net-cdn/296333/5 "2024-04-07T10:49:58Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
