There is many ways, but our browsers have now this capabilities built-in!
Example using a lib suncalc.js, the server must have CORS enabled to works this way!
Example, getting a lib from a CDN, after DOM load, directly available in the current context:
(async () => {
// Get and import the lib
await import('https://cdnjs.cloudflare.com/ajax/libs/suncalc/1.8.0/suncalc.min.js')
.then(function(){
// Lib ready to use
let times = SunCalc.getTimes(new Date(), 51.5,-0.1);
console.log("Golden Hour today in London: " + times.goldenHour.getHours() + ':' + times.sunrise.getMinutes() + ". Take your pics!")
})
})()