The Iframe is loading a JavaScript that is already loaded on the parent page but is not being fetched from the disk cache

My webpage has 4 iframes, all loading the same javascript file. However, when I checked the network tab in my browser's developer tools, I noticed that the javascript was being loaded 5 times from the server. I tried to set the iframes to load only after the javascript in the parent page had loaded, but I still encountered the same issue. Why is this happening?

  • The code of the parent page:

    <html>
    
    <head>
    </head>
    
    <body>
        <iframe></iframe>
        <iframe></iframe>
        <iframe></iframe>
        <iframe></iframe>
    </body>
    <script>
        var newScript = document.createElement("script");
        newScript.src = "https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.1/jquery.min.js";
    
        var srcs = ["html1.html", "html2.html", "html3.html", "html4.html"];
        document.getElementsByTagName("HEAD").item(0).appendChild(newScript);
        newScript.onload = newScript.onreadystatechange = function () {
            console.log("jquery.min.js loaded");
            var iframes = document.getElementsByTagName("iframe");
            for (var i = 0; i < iframes.length; i++) {
                var id = i;
                iframes[id].src = srcs[id];
            }
        }
        console.log("init");
    </script>
    
    </html>
    
  • The code within all iframe pages:

    <html>
    
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <meta http-equiv="X-UA-Compatible" content="IE=8">
        <meta http-equiv="Expires" content="0">
        <meta http-equiv="Pragma" content="no-cache">
        <meta http-equiv="Cache-control" content="no-cache">
        <meta http-equiv="Cache" content="no-cache">
        <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
    </head>
    
    <body>
        html1
    </body>
    
    </html>
    
  • Screenshot: Network tab in DevTool:

Answer №1

An iframe operates within a distinct context, similar to its own browser tab or window. This behavior seems perfectly reasonable in my opinion.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

What is the best way to evaluate user input against a string retrieved from process.stdin.on()?

I'm having trouble comparing a string with user input from process.stdin.on as it always returns false. //Let's say the user inputs 'hello' every time. process.stdin.on('data', userInput => { let text = userInput.toStrin ...

Transferring selected radio button values to Javascript

This is an example of HTML code snippet: <tr> <td class="g"> Gender </td> <td class="g_input"> <input type="radio" name="gender" id="settings_gender" value="Male" checked />&nbsp;&nbsp;Male ...

jqGrid display/hide columns options dialogue box

I am looking to implement a feature that allows users to toggle columns in my jqGrid. I came across a module for this purpose, but unfortunately, it is no longer supported in jqGrid 4.x. I have searched for a replacement module without success. Are there ...

What is the best way to deliver an HTML document in Express from a directory that is one level higher than my server folder?

I am facing an issue while trying to access an HTML file from my main directory through my Express server, which is located one level deeper in the server folder. Below is the configuration of my server code: const express = require('express') ...

Looking to achieve a scroll effect with mix-blend-mode using JavaScript?

I am seeking a method to adjust the background color of a specific element based on the background itself. While CSS offers the mix-blend-mode property, I am looking to specify the color manually. Ideally, I would like to achieve the same effect using an ...

A step-by-step guide to setting up a custom splash screen for React Native

Looking for assistance in setting up a splash screen in react-native specifically for Android devices. I've managed to successfully implement one for iOS, but I'm encountering difficulties when it comes to getting one to work on Android. I' ...

.slideDown Not Functioning Properly on my System

After successfully linking my index.html file to jQuery, I am facing an issue with the .slideDown code. I'm not sure if there is a problem with the code itself or if I didn't attach jQuery correctly. Can anyone help me troubleshoot this? Below i ...

Tips for dividing HTML code on a page into individual nodes

I am looking to extract the HTML content from a website and then parse it into nodes. I attempted the following code: function load() { $(document).ready(function () { $.get("https://example.com/index.html", function (data) { const loadpage ...

Dealing with an endless loop caused by a promise in AngularJS's ui router $stateChangeStart event

I am currently working on implementing authentication in my Angular application and I want to redirect to an external URL when a user is not logged in (based on a $http.get request). However, I seem to be stuck in an infinite loop when using event.prevent ...

Retrieve information following an Ajax call inside a pre-designed template

Upon rendering a page with data put together by EJS, the goal is to refresh a section (thirdRow) of the page whenever the user submits new data. The refreshed section should display both the newly submitted data and the existing data. Although I have obtai ...

YUI3 Searching with Selectors

I'm encountering an issue with selecting a single checkbox object in YUI3 based on its unique value attribute. In a table, there are multiple checkboxes with assigned unique keys to their value attributes. What should be the correct selector in YUI3 t ...

Tips for building a dynamic view using Angular

I am working on a project where I need to dynamically generate multiple horizontal lines using data from a JSON file, similar to the example in the image below. https://i.sstatic.net/MthcU.png Here is my attempt: https://i.sstatic.net/EEy4k.png Component. ...

Having trouble with AngularJS ngRepeat not functioning properly?

Currently, I am utilizing AngularJs to showcase Google maps with markers. Upon clicking a marker, I am aiming to display the details of the clicked marker. Here is the content of my Controller.js: function createMarker(latitude,longitude,name,address,lo ...

retrieve all users who are not currently in the group

I'm currently struggling to retrieve all users who are not members of a particular group within a many-to-many association. After investing several hours into researching and experimenting, I've developed the following code. However, it falls sh ...

Keep elements in position when their bottom edge becomes visible while scrolling

This task may appear intricate, but I will do my best to explain it! I want to create a continuous scrolling article display similar to Bloomberg Politics (), but with a slight twist. My idea is to have the current article's bottom edge stick to the ...

Guide on using webpack to import jQuery

When using webpack, is it necessary to install the jquery file from npm, or can I simply require the downloaded file from the jquery website? directory app/ ./assets/javascripts/article/create/base.js ./assets/javascripts/lib/jquery-1.11.1.min.js webpack ...

What is the reason AJAX does not prevent page from refreshing?

Can anyone offer some guidance on using AJAX in Django? I'm attempting to create a basic form with two inputs and send the data to my Python backend without refreshing the page. Below is the AJAX code I am using: <script type="text/javascript& ...

Guide to attaching a mouse click event listener to a child element within a Polymer custom component

I'm currently facing an issue where I am attempting to attach a click listener to one of the buttons within a custom element during the "created" life cycle callback (even attempted using the "ready" callback with the same outcome). Unfortunately, I ...

Utilizing Regex to Authenticate a CAGE Code

Our task is to create a RegEx pattern that can accurately validate a CAGE Code A CAGE Code consists of five (5) positions. The code must adhere to the following format: The first and fifth positions must be numeric. The second, third, and fourth position ...

submit content to an iframe on a separate webpage

Work has been a challenge for me lately as I try to achieve a specific task. The starting page features a textbox and a button. My goal is to post the value entered in the textbox to an iframe on a different web page called iframeholder. The catch is tha ...