Is it possible to load a .js file in one UIWebview and then utilize it in multiple instances of UIWebviews in iOS?

I am currently developing an iOS app that displays multiple charts in several UIWebviews using a JavaScript Library. The app sends data to the JS library, which then renders the charts based on the provided data.

The main issue I am facing is that each webview in the app is linking its own "portlet.js" file, causing memory usage to skyrocket as more webviews (charts) are added. This eventually leads to the app crashing after navigating through 4-5 pages of charts. I suspect that this is due to separately linking the "portlet.js" file in each webview.

Is there a way for me to link "Portlet.js" only once in a webview and have it accessible in other webviews as well?

Thank you in advance

Answer №1

In the project called "content", I have a reference (blue) folder that includes subfolders such as "css", "js", etc. This particular folder structure is utilized for all WebViews within the application.

let base = URL(fileURLWithPath: Bundle.main.resourcePath!).appendingPathComponent("content")
let webpage = """
        <html>
            <head>
                <title>Title</title>
                <meta charset="UTF-8">

                <link rel="stylesheet" href="css/article_container.css" type="text/css" media="all">
                <link rel="stylesheet" href="css/style.css" type="text/css" media="all">
                //...
            </head>
            <body>
                <div id="article_container">
                //...
                </div>
            </body>
        </html>
    """
// Ensure to use `loadHTMLString` with baseUrl parameter
webView.loadHTMLString(webpage, baseURL: base)

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

Assign the value in the text box to the PHP session variable

Currently, I am developing a PHP "interactive text game" as a part of my assignment project. My task involves creating a user interface where users input information (such as character names) into text boxes that appear sequentially as they complete the p ...

Is the expiration time for iOS TestFlight autorenewable subscriptions not working properly?

While testing autorenewable subscriptions in iOS 8 with Testflight, I have noticed an unusual "bug?" Apple claims that an autorenewable subscription for 1 month should expire after 5 minutes in the sandbox environment. However, in my case, the expiration ...

Deleting a row from the table with a single click on the X icon

Is there a way to delete individual rows in a table by clicking on a close icon instead of removing all rows at once? Additionally, I am looking for a better method to display rows in a table. You can view my current implementation here: link -> jsfiddl ...

What are some solutions for troubleshooting setInterval issues?

I have a h1 element with a v-for loop that displays items from my array in the following format: <h1 v-for="(record, index) of filteredRecords" :key="index" :record="record" :class="get ...

Calculate the minimum, maximum, and average values within an array containing nested elements

I want to calculate the min, max, and average values for nested data that already have these values precalculated. Essentially, I'm looking for the average of averages, min of min, and max of max. I have a large dataset that includes the min, max, an ...

How come I am getting only a single outcome when iterating through a dataset array?

I have a fetch API that returns an array of objects, and within those objects are nested arrays and other objects. My goal is to filter out only the objects that contain a specific value. Specifically, I want to retrieve objects with an id of 11 from the p ...

Guide on how to incorporate an external javascript file into an HTML button

I am currently working on an exercise through Udacity that involves creating an HTML form with JavaScript functions. The task is to input text into the form, submit it, and have it displayed on the webpage within a blue square. This exercise is designed to ...

just half of the four $_POST variables are actually assigned

Here is a simple form structure: <table class='table table-striped table-bordered table-hover' id='dataTables-example'> <thead> <tr> <th>1</th> <th>2</th> ...

Clicking the ASP button does not trigger the onclick event when a web user control is included on the webpage

I have been working on a web form application that I developed using the visual studio template. The template includes a content placeholder that gets replaced by the content of each accessed page. One particular page, which contains server controls like t ...

Click on the form to initiate when the action is set to "javascript:void(0)"

I am working on an HTML step form that needs to be submitted after passing validation and ensuring all fields are filled. The form currently has an action controller called register.php, but also includes action="javascript:void(0);" in the HTML form. What ...

Clarification on deconstructing Mobx objects for props

Is it possible to substitute { todoList } with props.todoList in the TodoListView component and also replace all instances of todoList with props.todoList to achieve the same outcome? import * as React from "react"; import { render } from "r ...

Choosing text input after adding a dynamic HTML row can be done by identifying the specific characteristics

I am currently working on a CodeIgniter project where I have implemented a purchase form that allows users to search for spare parts items using autocomplete in an input text field. The initial search functionality is working fine, but when I try to add a ...

The AngularJS ng-if directive is failing to function properly, despite the logged boolean accurately reflecting the

I created a custom directive that handles the visibility of text elements on a webpage. While this logic works correctly half of the time, it fails the other half of the time. Here is the code snippet from my directive: newco.directive 'heroHeadline& ...

Creating Eye-Catching Images by Incorporating Image Overlays Using Just One Image

I'm facing a bit of a challenge here. I need to figure out how to overlay an image onto another image using just a single image tag. Specifically, I want to add a resize icon to the bottom right corner of an image to let users know they can resize it ...

The refined search parameters do not appear on the OpenCart theme

Recently, while managing my online shop using the opencart cms, I decided to enhance the search functionality by adding filters to my products. I followed a tutorial that guided me through the process: link to tutorial After implementing two filters for s ...

The result of calling Object.keys(obj) is not being shown on the screen

I have come across a code snippet that functions perfectly fine in the console, however, it is not being displayed on the screen. Any assistance in resolving this issue would be greatly appreciated. {Object.keys(flags).forEach(product => { return ( ...

Updating the 'cornerRadius' property of a navigation button in IOS 7.0: A step-by-step guide

Is it possible to change the corner radius of the default button on the navigation bar? Alternatively, would it be better to create a custom button and place it on the navigation bar? NSDictionary *rightAttributes = [NSDictionary dictionaryWithObjectsAnd ...

ng-repeat to display items based on dropdown choice or user's search input

Utilizing $http to retrieve JSON data for display in a table. I have successfully implemented a search functionality where users can search the JSON data from an input field. Additionally, I now want to include a feature that allows users to filter the JSO ...

Utilize Google Drive and scripts to incorporate map images into a React application

I'm currently working on setting up an album feature on my react website for a friend, and I would like the images in the album to be linked to a Google Drive so that he can easily upload new images whenever he wants. After successfully inserting the ...

What is the best way to eliminate leading and trailing spaces from a text input?

I'm currently working on troubleshooting a bug in an AngularJS application that involves multiple forms for submitting data. One of the issues I encountered is that every text box in the forms is allowing and saving leading and trailing white spaces ...