Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

HTML

soo ao long tian
soo ao long tian
1,111 Points

hi i need help, how to hide our javascript file, picture or music file in the browser?

for example, I build an html file with some image and sound file, and i uploaded those file into a web server, after that the user can access those source file by press F12 on the keyboard, and downloaded all my hardwork, for example picture i design and sound file that i compose. is there a way to prevent this from happening? for example in this html game https://ft.o4games.com/ when we press F12, we couldn't see those source file, but if you open my game and press F12, u can see all my file in there, this is my game link, http://www.ebuymalaysia.com/ u need to press mouse left button to have the game start

2 Answers

Well, you can't really get "protect" your files if you share them with someone. If somebody can read something, there's always a way of copying it. Though all of that, you still own the files you made by copyright law. When somebody uses your work without permission, you can put a lawsuit on him.

Technically you may want to have a look at the DRM features of HTML5, though I think they are a bit too complicated for your project.

Best Regards, Philip

soo ao long tian
soo ao long tian
1,111 Points

thanks for replying, if u open https://ft.o4games.com/ and you press F12, you don't see any sprite file that those game used, but if you open mine http://www.ebuymalaysia.com/ , you can see all my sprite file in the there, how do they hide it? or at lease make it difficult to download, does it have something to do with database? if i store those file in database, will user will be able to see my file if they pressed F12?

soo ao long tian
soo ao long tian
1,111 Points

can i encrypt the entire website? will it work?

I'm sure you can find their sprites if you are skilled enough/put great efford to it. However, you can obfuscate it from normal users. Most basic one(which I personally REALLY do not recommend):

<body oncontextmenu="return false">
</body>

It is better to put some sort of encryption (maybe AES) to the images (Server-Side with PHP), and dynamically decrypt it on the client side. Also, obfuscate the JS Code.

soo ao long tian
soo ao long tian
1,111 Points

thanks, i will try to AES the image file

If you want to make it more difficult, AES the image with PHP and a key stored in the $_SESSION variable. Then, insert the key to the JS file dynamically.