2

My Angular application loads JSON files as search material using $http

$http.get('my.json').success(function(data){ ... };

Unfortunately, this method loads the JSON file in to the browser and allows the user to see it's content.

Safari screenshot Screenshot from Safari

I'd like to hide that file from the user.


To refine my question. I know that I won't be able to totally hide that data from the user. A user can easily write a script to scrape the data off my site. I just don't want to hand those files to the user so easily, to just let them sit there for him to just copy and paste.

2
  • I think you can use ng-hide attr to hide the same Commented Jul 23, 2014 at 8:08
  • 1
    If you're sending it to their browser, and they're interested and knowledgeable enough, they can see it; you can't hide it from them. If you absolutely need to keep data hidden from the user you can't send it to their browser. Commented Jul 23, 2014 at 8:11

2 Answers 2

4

Everything you sent to client is anyhow visible by client. There is no way to absolutely hide it from him.

All you can do is .zip or encode data on server and unzip or decode it on client. But even in this case all decoding mechanisms will be available to user and if he wishes and has some skills, he can decode it and access all data you send him.

UPD:

Ok, you want to uglify your data so client couldn't see it simple way.

You need to somehow encode data on server, send it encoded to the client, and decode on client so you could use it.

Checkout lz-string - it's js library that can archive / unarchive json strings, converting them to binary format, so data becomes unreadable. And it's pretty fast (I haven't noticed any delays encoding/decoding 2Mb strings - I use it to compress data and store it in localStorage).

It's as easy as LZString.compress(JSON.stringify(data)) to compress json and JSON.parse(LZString.decompress(data)) to decompress.

Only thing you need in addition - to find a server-side library that uses exactly this format. If you use NodeJS at your server, you can take lz-string itself. Otherwise, quick googling gave me solution for php - I think it's pretty possible to find solutions for other languages..

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

1 Comment

I updated my question with a refinement, I'd highly appreciate it if you could update you answer accordingly. Thanks for answering! :)
1

If you want the user to see only parts of the document, you should filter it on the server.

Create some kind of service/Api-function/etc. which loads the document and pass it the user information via ajax request. Now filter it depending on this user information and return the filtered data.

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.