0

If I have a static json file on my server, is it possible to extract only the required section of the json data using javascript without downloading the whole json file?

I understand that I can use serverside technologies to dynamically generate json data to based on what I want, but I just wanted to know if javascript can be used to extract data from a server json file without downloading the whole thing?

2
  • As far as I know, JavaScript provides no way to request a partial download. Commented Feb 6, 2013 at 15:13
  • Is your file very big ? Why do you bother ? Commented Feb 6, 2013 at 15:14

3 Answers 3

3

No, you can't do this client side as the browser called by javascript can only fetch a whole file.

If you really need to get only part of the file, you'll have to build server side code.

But check before by profiling that you need to do this optimization. And don't forget that fetching only part of a file would prevent the file from being cached and reused as a whole.

Sign up to request clarification or add additional context in comments.

Comments

1

For a static file on the server, how would JavaScript access it without downloading the whole file?

I'm afraid this is impossible. You could download the file and filter through the data on the client, or you could write server-side code to do the filtering for you, then output the result to the caller -- your client-side JavaScript code.

Comments

0

the answer is no, but if you could handle the json data on server side, you could create a json response when sending parameters on your ajax call to retrieve different results depending on the parameters you sent. These parameters would limit which sections you want.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.