The difference between the local host and the opening html file

What is the main difference between working with a server on a local host and opening a file, such as file:///Users/$user_name/$your_directory/index.html , if the backend is not used , and this is just the interface and contains html / css / js
How does this affect interaction with another server, i.e. Ajax requests?
I apologize if this is too broad, but I have not found a firm answer to these basic questions.

+5
source share
2 answers

Basically, assuming that at some point you are going to post the result on a real web server, the first corresponds to the target environment, and the second does not. Browsers process local files and files served from web servers (even localhost web servers) differently, although it is very similar. One aspect of this is encoding: when you retrieve a file from a web server, the process of determining what encodes the data is different from opening a local file.

How does this affect interaction with another server, i.e. Ajax requests?

This is one of the main ways in which they are processed in different ways, and even from browser to browser. A page loaded from the file:// URL has a null origin in terms of a policy with the same source code. Some browsers (such as Chrome) completely prohibit sharing Cross-Origin resources for a null source, even if the server you are trying to talk to has a wide-open CORS policy ( * ). Others (e.g. Firefox) allow origin null match the pattern.

In general, for best results, make sure your development environment matches your deployment environment in important ways. This means that you are doing your development using a web server process, not local files. Most IDEs will happily provide you with this process; if not, Apache or Nginx is not difficult to install.

+7
source

I don’t think it will be any difference. Buy there is an exception when using chrome! Sometimes I saw if some kind of CDN link was added to the html file, then it does not load into the html specifically in chrome, but if you try the psame file in FF or IE, it works. I ran into this problem and therefore I always put it under the local IIS website by default.

-3
source

Source: https://habr.com/ru/post/1258667/


All Articles