Home
Support Forums

Any way to update a JSON file on your site without having to redeploy the entire site?

Netlify site name: raidchamps
Live URL: https://raidchamps.com/

First I should explain my process…

I use a custom Netlify Plugin that builds a search index for my site in the form a JSON file, but this file can only be accessed after the site has been deployed. So after deploying the site, I have to copy the entire contents of the file and paste it into my JSON file in src/json/AlgoliaIndex.json and then I have to redeploy the site again to actually push the updated JSON content to the live site.

Is it possible to update this JSON file on my live site without having to redeploy the entire site twice?

If not, could you maybe suggest a better way than what I am currently doing?

Thanks,

Chris

Hi @raidchamps

Short answer is no.

If you are using Algolia have you looked at the algolia/algoliasearch-netlify plugin?

So I actually do not use Algolia anymore… I originally used them but I kept exceeding my operations limit way too early each month.

So now instead of copying the content of the JSON into my Algolia index, I copy it into src/json/AlgoliaIndex.json instead (I should probably change the name of this file lol).

I did NOT have to deploy the site twice when I was using Algolia because adding the JSON to my Algolia index did not require me to deploy the site again. After I saved the new index in my Algolia account, the changes would automatically appear on the live site.

Now that I am no longer using Algolia, I want to know how I could either…

  1. Update src/json/AlgoliaIndex.json without having to redeploy the entire site
    OR
  2. I need to figure out a way to generate the JSON locally before deploying it. That way I could update src/json/AlgoliaIndex.json before deploying it.

Thanks!

Your best option is possibly to build your site locally then deploy the built site to Netlify.

You could try using the pre-/post-build scripts to run another command (on Netlify) that generates and copies the file to the desired location.

Someone with more experience using/writing plugins (as you are using a custom one) may have further advice to offer in getting a better solution.

Is there a way I can get a Netlify plugin to run when building my site locally? I usually only build my site to test and make sure it won’t fail when deploying to Netlify.

That sounds great, can you point me in the right direction?

I wish I could take credit for the creating the plugin but I just took someone elses plugin and modified it for my purposes and do not fully understand how it works. I have reached out to the developer but he is too busy to help.

Yes, using Netlify CLI’s netlify build command.

I think @coelmay is talking about this:

Generally the index should be built by your SSG - for example in Hugo we could write a custom template that would generate the JSON file as we need it. You can possibly get some similar functionality in any SSG. If not, you would have to use a build plugin to read your website’s code and build an index from that - way more complicated than writing a template in my opinion.