Web Technology Basics

Under the browser's same-origin policy, which of the following URLs is considered to have the same origin as https://www.example.com/app/index.html?

  1. Ahttps://www.example.com/data/list.json
  2. Bhttp://www.example.com/app/data.json
  3. Chttps://api.example.com/app/data.json
Show answer and explanation

Answer: A. https://www.example.com/data/list.json

An origin is determined by the combination of three things, the scheme, the host name and the port number, and two URLs have the same origin only when all three match. The path does not matter, so /data/list.json has the same origin. Under the same-origin policy, a page's JavaScript in principle cannot read the contents of responses received from other origins. This prevents a malicious page's script from reading information from other sites where the user is logged in.

  • A. Correct. The scheme, host name and port number (443) are the same; only the path differs.
  • B. The scheme differs (http), and the default port number also becomes 80, so it is a different origin.
  • C. The host name differs (api.example.com), so it is a different origin even though it is under the same domain.
Practice this topic Back to topic

Books on Web Technology Basics Ad

As an Amazon Associate I earn from qualifying purchases.

More Web Technology Basics questions

  1. JavaScript on a page at https://app.example.com uses fetch to send a POST request with a body of Content-Type application/json to https://api.example.net/orders. Which of the following correctly describes how CORS behaves in this case?
  2. Which of the following correctly describes a Service Worker?
  3. For a page with responsive design that also supports smartphones, which of the following is the main purpose of writing <meta name="viewport" content="width=device-width, initial-scale=1"> in <head>?
  4. The response for a "my page" whose content differs for each user is given Cache-Control: private, max-age=60. Which of the following correctly describes the effect of this setting?
  5. When a web server compresses responses with gzip or Brotli before sending them, which of the following generally gains the least reduction in transferred data from compression?