1

I am hesitant to convert my script because I thought that getJson will affect my SEO. Aside from this, I feel that getJson is a bit slower. I just read in other forums that declaring global array is a bad practice. I just applied getJson in some of the pages in my website.

So all my pages has this basicdata.js containing the array to get all product data. I have 150 items in this array.

Any thoughts and suggestion to help me decide whether to include the data in .js file or load it via getJson?

jmozzart
  • 123
  • 8
  • 1
    Decide what? Whether to include your data in a .js file on the page load or load it via json after the page load? Depends on what your page *does*. Assuming the data size is non-trivial, loading with the page will mean the initial page load takes longer, so takes longer to display to the user while late-loading it (via ajax/getjson) will load the initial page sooner, giving a *perceived* increase in speed. Generally better to show *something* as soon as possible. But if it adds little time to initial load, then better to load with the page then you can use it immediately. – freedomn-m May 17 '23 at 07:16
  • 1
    yes.. i want to decide whether to include it in a .js file or via getjson. Thank you for your insights. – jmozzart May 17 '23 at 08:41
  • *I have 150 items in this array.* This seems not that much and I suppose the time difference is not even noticeable. So your decision is just personal preference. Also if this array is needed for the functionality of the page, it really doesn't matter.. – Wimanicesir May 17 '23 at 08:49
  • "*I just read in other forums that declaring global array is a bad practice*" - no, it is not. Manipulating global variables has a smell, but using global constants that just contain immutable data is totally fine. There will be barely any difference between a script loading the array as JSON or a script that just contains the data itself. – Bergi May 17 '23 at 13:00
  • 1
    SO Question: [Why are global variables considered bad practice?](https://stackoverflow.com/questions/10525582/why-are-global-variables-considered-bad-practice) – freedomn-m May 17 '23 at 13:21

0 Answers0