Skip to the content.
Q1. A server has a 16-core CPU, 64 GB RAM and 1 Gbps network connection. It can run a Python Flask application that can generate 500 HTML pages per second. Each page also has a 1 MB image that needs to be downloaded by the client. What will be the maximum number of requests per second that the server can handle?

Solution:

To find the maximum number of requests per second the server can handle, we need to evaluate the constraints imposed by the CPU, memory, and network bandwidth. Given the details:

  1. Server Specifications:

    • CPU: 16-core
    • RAM: 64 GB (not likely to be a bottleneck in this scenario)
    • Network: 1 Gbps connection
  2. Application Performance:

    • Can generate 500 HTML pages per second.
    • Each page includes a 1 MB image that the client downloads.
Step-by-step Analysis:
  1. CPU Capacity:

    • The CPU can handle generating 500 HTML pages per second, so CPU is not the bottleneck in this calculation.
  2. Method 1: Direct Conversion to MBps:

    • Network Bandwidth:

      1 \text{ Gbps} = \frac{1 \times 10^9 \text{ bits per second}}{8 \text{ bits per byte}} = 125 \text{ MBps}
      
    • Network Requirement per Request:

     \frac{125 \text{ MBps}}{1 \text{ MB/request}} = 125 \text{ requests per second}
    
  3. Method 2: Using Mbps and Mb:

    • Network Bandwidth:
     1 \text{ Gbps} = 1000 \text{ Mbps}
    
    • Network Requirement per Request:
      • Each request includes a 1 MB image, which is equal to 8 Mb (megabits).
       \frac{1000 \text{ Mbps}}{8 \text{ Mb/request}} = 125 \text{ requests per second}
    
Conclusion:

Both methods show that the maximum number of requests per second that the server can handle, based on the network constraint, is 125 requests per second. This is because the network bandwidth limits the number of 1 MB images that can be transferred per second, even though the CPU can generate more HTML pages.


Q2. Asynchronous updates refer to:
  1. loading part of a page in the background.
  2. operating without a system clock.
  3. using asynchronous circuit design for the processor in the data center.
  4. having separate files for HTML, CSS and JavaScript
Answer:

The correct answer is:

1. loading part of a page in the background.

Explanation:

Asynchronous updates typically refer to web technologies like AJAX (Asynchronous JavaScript and XML), where parts of a web page can be updated without reloading the whole page. This allows for a smoother user experience by loading data in the background and displaying it when ready.

learn more: AJAX W3School

The other options are unrelated:

One example of asynchronous updates:

Here's a simple example of how asynchronous updates can be implemented using AJAX in a web application to load data in the background without reloading the entire page:

HTML, JavaScript and XML code:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Asynchronous Update Example</title>
</head>
<body>
    <h1>Asynchronous Data Load</h1>
    <button onclick="loadData()">Load Data</button>
    <div id="dataContainer"></div>

    <script>
        function loadData() {
            const xhr = new XMLHttpRequest();
            xhr.open("GET", "https://jsonplaceholder.typicode.com/posts/1", true);
            xhr.onreadystatechange = function () {
                if (xhr.readyState === 4 && xhr.status === 200) {
                    document.getElementById("dataContainer").innerHTML = xhr.responseText;
                }
            };
            xhr.send();
        }
    </script>
</body>
</html>
Explanation:

Output: When the button is clicked, the browser fetches the data in the background and displays it without reloading the page.

What is XMLHttpRequest ?

XMLHttpRequest (XHR) is an API in web development that allows a client (usually a web browser) to interact with a server and exchange data asynchronously. It is primarily used for making HTTP or HTTPS requests to a server without refreshing the entire web page. This is key for creating a dynamic user experience, as it enables parts of a web page to be updated without a full page reload.

Key Features of XMLHttpRequest:
Basic Workflow:
  1. Create an instance of XMLHttpRequest.
  2. Initialize a request using open() method, specifying the HTTP method and URL.
  3. Set up a callback function to handle the response when the request completes.
  4. Send the request using the send() method.
  5. Process the response when the onreadystatechange or onload event fires.
Example Code:
// Create a new XMLHttpRequest object
var xhr = new XMLHttpRequest();

// Configure it: GET-request for the URL /data
xhr.open('GET', '/data', true);

// Set up a function to handle the response
xhr.onreadystatechange = function () {
    if (xhr.readyState === 4 && xhr.status === 200) {
        // Successful response; process the data
        console.log(xhr.responseText);
    }
};

// Send the request
xhr.send();
Explanation of readyState:
Common Uses:

Note: Modern web development often uses Fetch API or libraries like Axios for making HTTP requests, as they provide a more concise and powerful syntax compared to XMLHttpRequest.


Q3. DOM in the context of the web refers to:

document object model

document oriented meetings

data object mechanism

driver optional mode

Answer:

In the context of the web, DOM refers to the Document Object Model.

It is a programming interface for web documents, representing the structure of the document as a tree of nodes, where each node corresponds to a part of the document (such as an element or attribute). This allows programming languages like JavaScript to interact with and manipulate the structure, style, and content of web pages.


The Document Object Model (DOM) is a structured representation of a web page or document. Below are its key components:

1. Tree
2. Node
3. Element
4. Attribute
5. Text
6. Event
7. Document
8. Parent, Child, and Sibling Nodes
9. Document Fragment
10. DOM Manipulation

More information can be found in the MDN Web Docs.


These components together form the DOM's core structure, enabling the web page to be programmatically accessed, modified, and interacted with by developers.


Q4. Using JavaScript for updating the DOM will generally

increase load on the server.

increase load on the client.

increase load on the network.

decrease load on the client

Answer:

The correct answer is:

increase load on the client.

Using JavaScript to update the DOM typically happens in the user's browser (the client side), so it increases the load on the client rather than the server or the network. The server and network are generally not affected by these DOM manipulations, unless new data is being fetched from the server using AJAX or similar methods.


Q5. DOM updates can be used to

add text to the page.

remove text from the page.

add new entries to the database.

all of the above

Answer:

The correct answer is:

add text to the page.

remove text from the page.

DOM updates can be used to add or remove text on the page (through manipulating elements and text nodes). However, DOM updates cannot directly interact with the database. To add new entries to a database, a server-side operation (such as an API request) is needed in addition to DOM manipulation. Therefore, "all of the above" is not the correct answer.


Q6. Which of the following is most secure?

static HTML web page

PHP script on server

JS with native mode access

JS with only basic API access

Answer:

The most secure option is:

static HTML web page

Explanation:

Thus, static HTML is the most secure since it does not include the complexities and potential vulnerabilities associated with dynamic scripting languages like PHP or JavaScript.


Q7. Proper use of the constraint validation API can reduce the load on________.

client

server

network

all of the above

Answer:

The proper use of the constraint validation API can reduce the load on both the server and the network.

Here's why:

So, the correct answer is: Server and network.

In addition to the Constraint Validation API (which is commonly used for form input validation), HTML5 provides other APIs and built-in mechanisms for validation:

  1. Constraint Validation API
  1. FormData API
  1. Custom Validation with JavaScript
  1. Pattern Validation (HTML5 pattern attribute)
  1. HTML5 Input Types for Validation
  1. HTML5 required Attribute
  1. HTML5 min and max Attributes (for numeric fields)
  1. HTML5 maxlength and minlength Attributes
  1. HTML5 step Attribute

Summary of Common HTML5 Validation Methods:

  1. Constraint Validation API: Built-in client-side validation.
  2. FormData API: Allows programmatic manipulation and validation of form data.
  3. Pattern Validation: Using regular expressions with the pattern attribute.
  4. Input Types: Various input types like email, url, number, etc., come with built-in validation.
  5. Attributes: required, min, max, maxlength, minlength, etc., allow for specifying validation rules directly in HTML.

Together, these methods provide a comprehensive set of tools for form validation in HTML5, ensuring that data entered by users meets the specified requirements before submission.

Q8.A Python flask application is given below.
from flask import Flask 

app = Flask(__name__) 

@app.route("/")
def hello(): 
    return "<P> Hello World </p>" 

if __name__ == "__main__": 
    app.run(debug=True) 

Which of the following options is true?

  1. It is an example of static web page being used.
  2. It is an example of dynamic web page being used.
  3. The browser will not render any output as a webpage.
  4. None of the above
Answer:

The correct answer is:

2. It is an example of a dynamic web page being used.

Explanation:

Why the other options are incorrect:

  1. It is an example of a static web page being used: Incorrect. A static web page is served directly as an HTML file without any server-side code execution.
  2. The browser will not render any output as a webpage: Incorrect. The browser will render the output as a webpage displaying "Hello World".
  3. None of the above: Incorrect. Option 2 is the correct answer.

Example for static pages:

from flask import Flask,render_template

app = Flask(__name__) 

@app.route("/")
def hello(): 
    return render_template("hello.html")

if __name__ == "__main__": 
    app.run(debug=True) 

Q9. Which of the following statements is/are true in the context of 'DOM' updates?

Generating a page completely through DOM updates is good for the accessibility of the page.

Generating a page completely through DOM updates will make the page almost inaccessible.

HTML is generated on client side and it cannot be done by browsers with limitations.

All of the above.

Answer:

The statement that is most accurate in the context of 'DOM' updates is:

Generating a page completely through DOM updates will make the page almost inaccessible.

Explanation:
Why the Other Statements Are Incorrect:
Conclusion:

The best choices are:

Both statements highlight the potential challenges of client-side rendering and dynamic content for accessibility and browser compatibility.


Q10.Which of the following is/are true for the web browsers?

Javascript is the only language that can be made available on web browsers.

Web browsers usually have JS engines to run Javascript.

It is quite possible to build some other browser that supports languages other than Javascript.

None of the above.

Answer:

The accepted answers are:

  1. Web browsers usually have JS engines to run Javascript.

    • This statement is true because modern web browsers come with built-in JavaScript engines (e.g., V8 in Chrome, SpiderMonkey in Firefox, JavaScriptCore in Safari) to interpret and execute JavaScript code efficiently.
  2. It is quite possible to build some other browser that supports languages other than Javascript.

    • This is also true. While JavaScript is the dominant language for client-side web development, it is technically possible to create a custom web browser or modify an existing one to support other languages, such as WebAssembly (which is already widely supported), or even custom plugins for different scripting languages. However, JavaScript remains the standard for web development.
Explanation:

Q12. Which of the following statements regarding WASM is/are true?

WASM is a compiled form of Javascript.

WASM is an instruction set that is supported on many browsers.

It is not limited to JS and can be generated from other languages also.

All of the above

Answer:

The accepted answers are:

  1. WASM is an instruction set that is supported on many browsers.

    • This is true. WebAssembly (WASM) is a low-level, binary instruction format designed to run efficiently in web browsers. It is supported by all major modern browsers, enabling high-performance execution of code.
  2. It is not limited to JS and can be generated from other languages also.

    • This is also true. WASM is not tied to JavaScript; it can be compiled from various programming languages, such as C, C++, Rust, Go, and many others, making it versatile for web and non-web applications.

Explanation:

Conclusion: The correct statements are:


What is WSGI ?

WSGI (Web Server Gateway Interface) is a specification that defines how web servers communicate with web applications in the Python programming language. It acts as an interface between web servers and Python-based web applications or frameworks, facilitating a standard and consistent way to serve web content.

Key Points About WSGI:

  1. Purpose: WSGI was created to standardize the way Python web applications and web servers interact. Before WSGI, Python web frameworks and servers often had compatibility issues because each framework had its own method of communication.

  2. Specification: It is not a library or a framework but a specification defined in PEP 333 and later updated in PEP 3333 to support Python 3.

  3. Components:

    • Web Server: Receives HTTP requests and forwards them to the application via WSGI.
    • WSGI Application: Processes the request and returns a response back to the server.
    • WSGI Middleware: Optional layers that sit between the server and application, adding functionality such as request handling, authentication, or data compression.
  4. How It Works:

    • The web server passes an environment dictionary and a callback function (start_response) to the WSGI application.
    • The application processes the request using the environment information and returns an iterable that contains the response body.
    • The start_response function is used by the application to send HTTP status and headers back to the server.

Example of a Simple WSGI Application:

def simple_app(environ, start_response):
    # Status and response headers
    status = '200 OK'
    headers = [('Content-type', 'text/plain')]
    start_response(status, headers)
    
    # Response body
    return [b"Hello, WSGI World!"]

Why WSGI Is Important:

Common WSGI Servers:


Difference Between Synchronous and Asynchronous Updates in Frontend

In frontend development, synchronous updates and asynchronous updates define how the browser handles UI changes and communication with the backend.


1. Synchronous Updates

Example (Synchronous)

💡 Imagine you're ordering food at a restaurant:

  1. You place an order at the counter.
  2. You stand there waiting until the food is ready.
  3. Once the food is ready, you take it and leave.

👉 In frontend terms, this means when you click a button, the whole page freezes until the request is completed.

Code Example (Synchronous)

function fetchData() {
    let response = fetch('https://example.com/data'); // This blocks execution
    console.log("Data fetched!");
}

fetchData();
console.log("This message waits until data is fetched!");

👎 Issue: The browser waits for fetch() to complete before printing "This message waits until data is fetched!". This can freeze the UI.


2. Asynchronous Updates

Example (Asynchronous)

💡 Imagine you're ordering food at a restaurant with a buzzer:

  1. You place an order and get a buzzer.
  2. You sit and relax while waiting.
  3. When the food is ready, the buzzer rings, and you go to pick up your food.

👉 In frontend terms, you can click a button, continue using the page, and get a notification when data arrives.

Code Example (Asynchronous)

async function fetchData() {
    let response = await fetch('https://example.com/data'); // Fetch happens in background
    console.log("Data fetched!");
}

fetchData();
console.log("This message appears immediately!");

👍 Advantage: The "This message appears immediately!" is printed before data is fetched, meaning the UI stays responsive.


Key Differences

Feature Synchronous Asynchronous
Execution One step at a time (blocking) Multiple tasks at once (non-blocking)
UI Freezing? Yes, if an operation is slow No, UI remains responsive
Example Waiting in line at a restaurant Ordering food and waiting for a buzzer
Best Used For Small, quick tasks Network requests, animations, background updates

Conclusion:
Asynchronous updates make web apps faster and more user-friendly, especially when dealing with API calls or background tasks.