0

I was working on a Angular JS project. Basically it is a purchased theme with Angular JS, HTML, Bootstrap etc. when i tried to run it directly on browser it is broken. but when i run the same in my local server, it works fine.

I understand the importance of setting up a local server when we work on a project with server side language like PHP, .NET. what i am really confused is, why do we need to set up local server to run javascript or any javascript frame work?

Thanks in Advance.

Sha
  • 1,826
  • 5
  • 29
  • 53

2 Answers2

0

I would like to do these examples by access "file:///C:/TempProjects/GameOfCards/index.html#/" on local computer, but most browsers cannot access these files on local computer do to Cross Origin issues. Here a StackOverflow question and answer that describes this issue: Cross origin requests(CORS) are only supported for HTTP but it’s not cross-domain. So we need a web server

There is another way, by adding a switch in your browser(chrome in this case)-

--allow-file-access-from-files

But, I suggest, running a simple server is the best way of working with things. Hope it helps. Happy Coding.

Community
  • 1
  • 1
bozzmob
  • 12,364
  • 16
  • 50
  • 73
0

it happened for me . and I got that , when you run a js project directly , the address of some dependencies will change . for example your index is in c://www directory . if you want to open a html file which it's address in routing is in c://www/public/... the routing would be different . because when run on a server the www directory is running and your home directory is that . but when you run directly, your home directory is where your index file is ...