preface

Because learning cross-domain needs to configure the local server, which may be more troublesome, so I wrote most of the cross-domain simple demo according to the blog on the Internet, which can run locally by myself without configuring the server. My understanding of cross-domain just lies in the blog articles on the Internet at the beginning. By writing these demos that can be run locally, I have a more direct understanding of cross-domain. I hope these demos will be helpful to you.

Github address: github.com/FatDong1/c….

Multiple cross-domain demos

  • CROS cross-domain

  • The json cross-domain

  • PostMessage cross-domain, new HTML5 API

  • Window. The name across domains

  • The location. The hash across domains

  • Document. The domain across domains

  • Back-end proxy The proxy is cross-domain

    • Demo1, set up the proxy on the back end using the HTTP-proxy-middleware plug-in

    • Demo2, which does not use plug-ins to configure proxies, more primitive explains the principle of proxy cross-domain

  • Websocket cross-domain

advantages

  • By running Demo locally, you can quickly understand a variety of cross-domains.

  • The demo is easy to understand and includes many comments.

  • Low barriers to learning.

The principle of

The express framework of nodeJS is used to generate servers on ports 3000 and 3001 for cross-domain access.

Project Operating environment

Global installation

  • nodeJS

  • npm

  • git

Learn the basics of these demos

  • Git Clone project to local

  • A little nodeJS knowledge, most of the comments in the node knowledge, if you do not know nodeJS can also go to learn these demos.

Study suggest

When learning one of the cross-domain methods, it is recommended to run the demo in your project while searching for blog articles on the web to learn the cross-domain method, which will help you quickly and deeply understand cross-domain. Since there are plenty of articles on the web detailing cross-domain knowledge, but few demos that can be run locally, I won’t bother with cross-domain knowledge here.

The last

If there are any mistakes in the demo, feel free to comment on them, and if you can’t explain anything, just text me in the SegmentFault or gihtub Issue.

This article has been synchronized to my blog – www.xuhaodong.cn/arti…