hiding javascript code or get it outside root folder? - javascript

I am developing an application and have some important information inside the code like IPs and stuff which has to be private. I use apache web server as a server and wanna know if there is any way hide a javascript code or moving it outside root folder ?

No, by definition. Javascript code is run on the client's computer. That means that the client must have access to the Javascript source for it to work. You could use AJAX to hide certain data until it is needed, but even then the client (and any user with Firebug) would be able to view it.

The only way to "hide" it would be through some sort of obfuscation utility or to minify the javascript. But, unfortunately, once the javascript code makes it to the browser. There is not much you can do about it.

Related

What language can I use to read directories and files from an HTML page?

I'm continuing the project I talked about in another thread here, but at the moment I have stopped because I can't figure out how to dynamically add content to the page. It's supposed to be a webapp that runs locally (it won't be hosted on a domain).
I thought I'd be able to do it with JS, however I found out it can't read files for security reasons. What I was planning to do was get a list of all the files and folders inside a given directory (using JS), then append a div for each folder (with more stuff inside) inside the content area of my page. Seeing how I couldn't do that with JS, I thought maybe I could do it with PHP using the same approach, but I didn't like the idea of having to run xampp just for this... if there's a way to have PHP running without xampp and/or a server, then it'd be great, but so far I haven't found anything about that... except downloading PHP, but I have no clue how to "use" the console from the browser and then have it append the divs to the page, since the console and the browser are "separated".
To make it a little more clear: is there a way to run PHP without a server, and if not, what other languages can I look up to?
At this point I'd also like to know how websites such as clipchamp.com work. Do you guys have a clue about that?
In order to run PHP, you'll indeed need a server with the right permissions on the folder.
For small local projects, I've seen Node.js used, the learning curve isn't too steep if you already know JS. Check out the fs module in Node for access to the filesystem.
I thought I'd be able to do it with JS, however I found out it can't read files for security reasons.
It can, just not when the JS itself is executing in a web browser. JS running in, for example, Windows Scripting Host or NodeJS would have no problems.
if there's a way to have PHP running without xampp and/or a server
You can run PHP from the command line, but if you want the output to be rendered in a browser then you really need to be dealing with HTTP, which requires a server.
There is always the option of PHP's built-in webserver.
is there a way to run PHP without a server, and if not, what other languages can I look up to?
It doesn't matter what language you use. You'll find it hard to pick one that can't read the file system. They will all suffer from the same limitations when it comes to interacting with a web browser though. You need to be talking HTTP.
That is the whole concept of a browser. A browser can not give more permission to the system then the user of the browser does.
You have afaik two options: Use a server on the machine you want to manipulate (there are all kind of flavors, you can use nearly every language for building a server) or use/create a browser plugin that can do it (Silverlight can have access to the file system under some restrictions).

Create JavaScript with Umbraco

Do you know if there is a way to create a javascript or PHP file in Umbraco?
By this I mean that I would like to have the user populate fields in the same was as creating a page, but for it to output as .js or .php rather than the usual .aspx
Many thanks!
I don't see any reason why you couldn't; you could use a controller to output as pretty much anything by setting the mime-type.
I'd be wondering though what your use-case for generating PHP files would be though; the server would still need to process the PHP script somehow; which may not be a trivial task (unless you just want to generate the PHP file for download/display the code) as it isn't client-side script at all.
JavaScript on the other hand is entirely a different matter - as it's processed client-side you could just point the browser at a url that happens to deliver the generated JavaScript. You could even render the JavaScript out from a WebApi end-point and the browser client would quite happily consume it.

facebook's all.js is too big, is there a alternative

Facbook's all.js is too big. I just need the login part of it. Is there a way. Also is there a way to check if the user is loggedin without using all.js on the client side.
Facebook's all.js is too big.
Is it? They are doing everything they can to improve the download size of their script (not only for that particular one, but also for scripts embedded f.e. in the like button iframe, there’s some interesting blog posts about that on the net). It’s as big as it needs to be for the functionality it offers.
I just need the login part of it. Is there a way.
No, there is no way of just picking the cherries out of it. They have assembled all the functionality that is most commonly used in websites that use the Facebook API in that one script. Splitting it up into multiple scripts so that everyone could only load “just what they need” would hit performance even worse, if people had to embed multiple scripts if they needed more than one functionality.
Also is there a way to check if the user is loggedin without using all.js on the client side.
Only server-side then.
Your best chance is to do your entire development with all.js
Then run your code through a dead path removal script (Google Closure comes to mind).
This will remove everything that is not needed in your code workflow.

Using Javascript to determine whether a file exists, LOCALLY

got some great feedback last time.
I'm essentially setting up a Wiki-type system on my local computer. I'm linking between HTML files, with some already existing and some not. I'm using XMLHttpRequest to check to see if the files exist.
The problem comes when I need to check files that are in different directories. I've come to find out this is a security thing in place. However, I'd like to disable it if possible, just for my local files. It seems rather odd that I can't have simple Javascript that returns the text on any web page at all, but even more so on my own computer.
I don't have any sort of server software running, just a bundle of HTML files with Javascript in them.
Thanks in advance!
javascript can not talk to the local filesystem. The reason for this is to keep people from writing destructive scripts that break your computer.
If this isn't a learning exercise, perhaps you might be interested in TiddlyWiki?
As you mention your self, "this is a security thing in place". In general, JavaScript is not allowed to access local files as it violates the sandbox.
However, have a look at these SO posts that discuss a few possible solutions:
Can JavaScript access a filesystem?
Local file access with javascript
You can also have a look at this HTML5 feature:
Reading local files in JavaScript

Play framework auto javascript and CSS minifier

Does anyone know a good play plugin that automatically minifies javascript and css to attach to a production play server?
I've found this one, but I guess there are more out there:
https://github.com/greenlaw110/play-greenscript
The main problem I see here is that the having javascript being generated from the play side, the plugin would have to detect JS code that gets generated on the fly. Mainly because I'm writing values directly into the javascript like:
function foo${handlerID}(someVar){
var x = ${some_val};
(...)
}
var t = foo${handlerID}('bar');
The reason we do minimizing/compressing/merging for css/js/img is because we want to save the network bandwidth and accelerate application performance, lower the server's load and make the user be more happy.
When you are putting those groovy variables into your javascript code you are shifting to the other way, i.e. making the server slowing down. Because each request will get a different javascript file to be downloaded, and the user will be no longer benefit from the local cached js copies. For the same reason using greenscript or any other minimizing tool to compress it is meaningless, because each time your need to compress and merge again instead of get it directly from cache.
If there are cases that you HAVE TO put the groovy variables into some javascript code, you'd better separate them from other parts (which should reasonably be most the majority). By doing that you could still using greenscript or press to process your static js files and leave the dynamic parts stay inside your view.
Check out the press module.
As long as the generated Javascript and css are in their separate own respective files you should be able to minify them automatically.

Categories

Resources