Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

208
Views
CORS Error when including scripts in Node JS Pug Template

I have an express server which uses the PUG as a template engine. I am trying to add tailwind CSS using the cdn but I'm getting a cors error like this:

Error: Access to script at 'https://cdn.tailwindcss.com/' from origin 'http://localhost:3000' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.

In my pug template this is my base file where I m trying to include the script:

html
  head
    block head
      meta(charset='UTF-8')
      meta(name='viewport' content='width=device-width, initial-scale=1.0')
      link(rel='stylesheet' href='/css/style.css')
      link(rel='shortcut icon' type='image/png' href='/img/favicon.png')
      link(rel='stylesheet' href='https://fonts.googleapis.com/css?family=Lato:300,300i,700')
      title A & N Tours | #{title}
  
  body
    // HEADER
    include _header
        
    // CONTENT
    block content
      h1 This is a placeholder heading
      
    // FOOTER
    include _footer
    
    script(src="https://js.stripe.com/v3/" crossorigin="") 
    script(src='/js/bundle.js')
    script(src="https://cdn.tailwindcss.com" crossorigin="" defer) 

My route handler function:

  const tours = await Tour.find().limit(3);
  res.status(200).render('homepage', {
    title: 'Home',
    topTours: tours
  })
});
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

The resource that you request from tailwindcss.com does not come with CORS headers. But because of the crossorigin="" attribute, the browser expects them.

The problem goes away if you omit this attribute

script(src="https://cdn.tailwindcss.com" defer) 

Is there a particular reason why you set the attribute?

The following HTML page loads without problems:

<!DOCTYPE html><html>
<head>
  <script type="text/javascript" src="https://cdn.tailwindcss.com" defer>
  </script>
</head></html>
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!