How Should I Store Global Values for My Static Site?

0
6
Asked By WebDevExplorer92 On

I'm new to web development and looking for advice on how to manage global 'environment' values for a static site. I initially thought .env files could be the solution, but after asking in a web dev Discord, I got mixed feedback about using them for non-sensitive data since that's not their primary purpose. I then considered using JSON files, which I understand are good for storing and transferring data, but I'm unsure if that's appropriate for a static site that doesn't use a backend. Ideally, I want a lightweight method to manage values that I might need to change frequently, like file paths depending on where my site is hosted (e.g., GitHub Pages vs. Netlify). What's the best approach for this?

1 Answer

Answered By CodeWhisperer88 On

A great approach is to let your build process handle environment differences. If you're loading a JSON file on every page, that’s doable, but it might be better to handle it at build time to keep things clean and efficient. Plus, if you package your site, it avoids overloading the client with unnecessary data loads.

CuriousCoder72 -

Thanks for the insight! I think understanding this before I go too far is super helpful. I’ll definitely dive into how to set that up!

Related Questions

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.