Hey all,
Just a bit of a random question regarding best practices. I am finishing making a website and and using a local JSON file to store data I need in one of the pages.
I have decided to keep the data in a separate JSON as it has the potential to become pretty big and I want to account for the future so it isn’t an issue for me or the next person who develops the project.
In order to do so I have used a simple fetch query to get the data:
fetch('./assets/json/spices.json')
.then(res => res.json())
.then(data => {
console.log(data)
})
.catch(err => console.error(err));
However, I am aware that I can also export the data as a module by saving it as a .js
filetype and using the ES6 export/import as follows:
let spices = await import('./assets/json/spices.js')
.then(res => res.json())
.then(data => {
console.log(data)
})
.catch(err => console.error(err));
To me it seems that both approaches achieve the same results (asynchronously get the data) however, the ES6 import/export module method, to me, seems to use more code.
Which would be considered to be best practice? Or is there another method which I have missed?