0

I have a JSON file which is storing some information, and another JavaScript file which show those information on the page...

How can I do something that visitors of my website can't see the JSON file from it's URL, but that JavaScript file can access it?

P.S.: I changed the permissions of that file to 640, but it stopped the JavaScript file to show the result...

  • Assuming the Javascript is being executed remotely in the user's browser (ie. not server-side Javascript like Node.js), I don't think it's possible, because the user's browser needs to be able to access the JSON for the client-side to work. You could try using some authentication method, but that would only slow someone down who wanted to get it, not stop them. – nathangiesbrecht Aug 19 '15 at 15:58
  • @nathangiesbrecht Is there anyway to make that JSON array invisible to see (like an empty index.html), but the browser can read the code? – MR. Garcia Aug 20 '15 at 9:34
  • Unfortunately, no. Anything that will need to be available to the user for your app/page to work, will need to be available to a user/browser. Can't really hide something from people and make it available at the same time. – nathangiesbrecht Aug 20 '15 at 13:49
1

... visitors of my website can't see the JSON file from it's URL, but that JavaScript file can access it?

JavaScript is the wrong thing to be using if you're dealing with secure files. It sounds like you have javascript code that fetches special JSON code from the server you don't want guests to see, but if guests view source code and figure out the URL to the special code, they can access the URL directly in their browser and see everything.

You're better off using a database system to store data that users can't see. Look into MySQL.

If that doesn't work for you, you can try creating files and saving them at a location on the server inaccessible to users then use a script that reads them and only prints information users can see.

  • Actually, my website is not THAT MUCH big to make a new database for it... It's a static page which loads ALL of its data from a JSON array! So if any visitor can see that JSON array, they simply can see all the information of the website! – MR. Garcia Aug 20 '15 at 9:32
  • Then you're better off turning the JSON array into a file that only a script (such as a PHP script) can process for you. That way, no hidden info is exposed. – Mike Aug 20 '15 at 16:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.