Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript

How do you protect your ember script from being stolen?

How do you keep you ember script from being stolen? Do I use uglifier or minifier? Is there a better way?

4 Answers

I figured it out. You can prevent download and view of the code by blocking it with htaccess.

RewriteEngine on
RewriteCond %{HTTP_REFERER} !http://your-domain\.com/.* [NC]
RewriteRule ^.*js$ - [F]

I am not entirely sure that will prevent the file from showing up in dev tools. This will however, prevent direct access to the file.

You can use an uglifier and/or minifier to make your code harder for someone to read and understand, but their real benefit is to reduce the size of the JS file you send out with your webpage.

The way that JavaScript works on the client side is that you send your source code to the client and their browser runs it. Because of this, you cannot control the environment you code runs in, e.g., they may use an older browser that doesn't support a feature you used, and if the user knows how to use their browsers developer tools, they will be able to read and download any file you send them.

I don't think there is any way to keep any source code from being copied. You can use tools to make your code hard to read but that still would not keep the files from being accessible.

Why do you feel the need to want your code from being stolen or copied?

htaccess will block it. I saw someone use it.

Hassam Uddin
Hassam Uddin
8,204 Points

Code that has to do with the client side can't be kept away at all. You can make it very hard for people to access server code by putting it in a separate folder than the root folder. But, since most client side code needs to be accessed via html, it's impossible to keep it away from the views of people with experience with their browsers developer tools.