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

365
Views
how to import variable from javasvript to html script tag

I'm making webpage with django templete. In the HTML script tag, I make a variable which contains geojson data, so that it is too long to be contained in a single file.(about 10000 lines) So I want to detach it another place. var "areas" in the image is it.

enter image description here

So I want to detach that variable to another file(maybe .js file? any format no matter.)

  1. Where I should save that variable? is it .js file?
  2. How can I import that variable in HTML script tag?

Thanks for your help!

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Just Use A JS File with just the variable and importing it through script tag would work fine. Like if it was saved in areas.js use the code
<script src = "areas.js"></script>
in the body tag then you can just the use variable like normal in scripts

about 4 years ago · Juan Pablo Isaza Report

0

You can put that data in a .json file on your server. Than do something like following to fetch the json and parse it.

fetch('http://example.com/movies.json')
  .then(response => response.json())
  .then(data => {
     // Use data in your app.
  });

Reference: https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch

You can also use async/await to avoid the .then and callback.

async function fetchMoviesJSON() {
  const response = await fetch('/movies.json');
  const movies = await response.json();
  // Use the data in your app.
}
fetchMoviesJSON();
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!