Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3790074
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T12:15:26+00:00 2026-05-19T12:15:26+00:00

I know it’s impossible to hide source code but, for example, if I have

  • 0

I know it’s impossible to hide source code but, for example, if I have to link a JavaScript file from my CDN to a web page and I don’t want the people to know the location and/or content of this script, is this possible?

For example, to link a script from a website, we use:

<script type="text/javascript" src="http://somedomain.example/scriptxyz.js">
</script>

Now, is possible to hide from the user where the script comes from, or hide the script content and still use it on a web page?

For example, by saving it in my private CDN that needs password to access files, would that work? If not, what would work to get what I want?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T12:15:27+00:00Added an answer on May 19, 2026 at 12:15 pm

    Good question with a simple answer: you can’t!

    JavaScript is a client-side programming language, therefore it works on the client’s machine, so you can’t actually hide anything from the client.
    Obfuscating your code is a good solution, but it’s not enough, because, although it is hard, someone could decipher your code and "steal" your script.
    There are a few ways of making your code hard to be stolen, but as I said nothing is bullet-proof.

    Off the top of my head, one idea is to restrict access to your external js files from outside the page you embed your code in. In that case, if you have

    <script type="text/javascript" src="myJs.js"></script>
    

    and someone tries to access the myJs.js file in browser, he shouldn’t be granted any access to the script source.
    For example, if your page is written in PHP, you can include the script via the include function and let the script decide if it’s safe" to return it’s source.
    In this example, you’ll need the external "js" (written in PHP) file myJs.php:

    <?php
        $URL = $_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'];
        if ($URL != "my-domain.example/my-page.php")
        die("/\*sry, no acces rights\*/");
    ?>
    // your obfuscated script goes here
    

    that would be included in your main page my-page.php:

    <script type="text/javascript">
        <?php include "myJs.php"; ?>;
    </script>
    

    This way, only the browser could see the js file contents.

    Another interesting idea is that at the end of your script, you delete the contents of your dom script element, so that after the browser evaluates your code, the code disappears:

    <script id="erasable" type="text/javascript">
        //your code goes here
        document.getElementById('erasable').innerHTML = "";
    </script>
    

    These are all just simple hacks that cannot, and I can’t stress this enough: cannot, fully protect your js code, but they can sure piss off someone who is trying to "steal" your code.

    Update:

    I recently came across a very interesting article written by Patrick Weid on how to hide your js code, and he reveals a different approach: you can encode your source code into an image! Sure, that’s not bullet proof either, but it’s another fence that you could build around your code.
    The idea behind this approach is that most browsers can use the canvas element to do pixel manipulation on images. And since the canvas pixel is represented by 4 values (rgba), each pixel can have a value in the range of 0-255. That means that you can store a character (actual it’s ascii code) in every pixel. The rest of the encoding/decoding is trivial.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know I could go and read the source code of the Framework, but
I know the input have the maxlength, but I would like to have minlength
I know we already have many posts about this topic, but I just cannot
I know that this php code is bad <?php $id=$_SESSION['id']; ?> but it saves
know nothing about php, but I have this script that reads a folder and
I know that you can use DirectoryIndex example.html in .htaccess, but what I need
I know that this question has been approached under different ways, but I have
Know this might be rather basic, but I been trying to figure out how
Know if it's possible to access the iPhone compass in Safari using JavaScript? I
I know you can not set a key value dynamically, but what about the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.