Accessing Javascript/Jquery script files on the disk in your browser

All the modern browsers have implemented a security protocol that prevents the website to access files from the disk. It's a really important security measure that forbids the websites to snoop into your disk and steal your 'data'. However sometimes you want to load the files anyway. May you are developing a web app and you want to load libraries stored on your disk. This security protocol will hinder this action.

You can use work arounds by setting certain flags of the browser that will disable these security fences but the catch is you will become vulnerable to the attacks. I don't advice disabling security in your browser. The workaround that I have found is very secure.

So for example if you want to reference a Jquery file on your disk, trying to access it with

src="file:///path/to/your/file.js"

wont work.

So the easiest workaround that doesn't require alot of effort is to serve these library files or any other file that you want to load by serving them via a local server on your system. So your next question will be how can I do that? Well it's pretty simple. Following steps should get you up and running in just a minute.

1. Install wamp/xamp or any other program of your choice.<
2. Put the files that you want to be served by the server in the /path/to/wamp/www/yourfile.js
3. Start the wamp server.
4. Put the local host path to server file where ever you want to access it. Eg. src="http://localhost:81/yourfile.js"


Voila! You should be able to fetch the files locally now.

Comments

Popular posts from this blog

Noir A8: Battery Friendly Jelly Bean Rom

ICS Themed Rom For Noir A2

Exploring Redux in React Native: Building a Test App with Example Code