Search code examples
cssexpresssafaripug

Pug template not loading CSS on Mac in safari


Safari on Mac (Ventura 13.2.1) neither loads CSS nor favicon in combination with Pug.

Please help find a solution.

Error:

Unsafe attempt to load URL https://localhost:3000/img/icons.svg from origin http://localhost:3000. Domains, protocols and ports must match.
Failed to load resource: An SSL error has occurred and a secure connection to the server cannot be made.

Network tab in developers mode:

Summary
URL: https://localhost:3000/css/style.css
Status: —
Source: —
Initiator: 
localhost:1

Impression:

Seems that the problem is related to SSL.

File Location

root>public>css>style.css

Example of code

app.use(express.static(path.join(__dirname, 'public')));
doctype html 
html(lang='en')
    head
      link(rel='stylesheet' href='/css/style.css' type='text/css')
      link(rel='shortcut icon' type='image/png' href='/img/favicon.png')

What has been done so far:

I googled the issue and it looks like developers experience a similar issue. I tried proposed solutions and it has not fixed the issue.
I switched to chrome and everything works as it should.

Some examples of what has been tried:

  res.set(
  'Content-Security-Policy',
  "default-src 'self';font-src fonts.gstatic.com;style-src 'self' 'unsafe-inline' fonts.googleapis.com"
  );
style
  include css/style.css

Solution

  • It could be that HSTS for localhost is cached by Safari.

    Or it is predefined by your server/express/helmet.

    Disable it through helmet. For example like this:

    app.use(
        helmet({
            hsts: false,
        })
    );
    

    And clear Safari's cache in the Settings: Privacy -> Manage Website Data