-1

I want to prevent my javascript code from page source and even when someone tries to open javascript code using URL it should block or else it should display a message that cant display code.

Is there any way to prevent my code from unwanted users and I m Using codeigniter framework?

The below is the javascript code which i want to prevent from unwanted users. i can get a below code by typing this link in browser
abc.com/js/abc.js

I m Using codeigniter framework

FusionCharts.ready(function () {

    var iexsolorchart = new FusionCharts({
        type: 'MSCombiDY2D',
        renderAt: 'iexsolar-chart-container',
        width: '100%',
        dataFormat: 'jsonurl',
        dataSource: base_url+'rec/recData/1/1'
    });
    iexsolorchart.render();

    var iexnonsolorchart = new FusionCharts({
        type: 'MSCombiDY2D',
        renderAt: 'iexnonsolar-chart-container',
        width: '100%',
        dataFormat: 'jsonurl',
        dataSource: base_url+'rec/recData/1/2'
    });
    iexnonsolorchart.render();  

});
var loaded = false;
$("#pxi_tab").click(function (){ 
    if(loaded == true) exit();
    FusionCharts.ready(function () {
        var pxisolorchart = new FusionCharts({
            type: 'MSCombiDY2D',
            renderAt: 'pxisolar-chart-container',
            width: '100%',
            dataFormat: 'jsonurl',
            dataSource:base_url+'rec/recData/2/1'
        });
        pxisolorchart.render();
        var pxinonsolorchart = new FusionCharts({
            type: 'MSCombiDY2D',
            renderAt: 'pxinonsolor-chart-container',
            width: '100%',
            dataFormat: 'jsonurl',
            dataSource: base_url+'rec/recData/2/2'
        });
        pxinonsolorchart.render();
    });
    loaded = true;

});

2 Answers2

1

Dont think there is a way you can do this with javascript.

Javascript is a way for having less code running on your server and make that work on the client freeing resources on you server.

Think of it like this. If you had all the code on your server the more users you would have the more work your server would have to perform. By using javascript a lot of work can be done on the client side freeing up resources on you server.

  • is it possible or no?? do you have any solution for this.. – Amol Patil Jan 02 '15 at 12:11
  • 1
    There are some things you can do. But javascript is designed to be run in the client. Try these tools: YUI Compressor. Google Closure Compiler or UglifyJS. Some of these try to make the code harder to read. But there are tools online to 'beautify' it back again and someone can see it. – João Martins Jan 02 '15 at 12:18
  • Javascript isn't just about freeing server resources. I wouldn't say that's even its main purpose. In any case this doesn't really answer the question. – nnnnnn Jan 02 '15 at 12:35
  • I agree with you i am just saying that due to this fact clients can see it. – João Martins Jan 02 '15 at 12:36
0

One thing you can do is minify your script so, even if anyone gets code , it will be hard for him to go through it.

sanguine
  • 24
  • 5