Understanding the functionality of script tags during the PreRender phase is crucial

I am currently exploring the possibility of reading script tags within the PreRender event of a master page. I have been successful in extracting CSS links, but I am facing difficulties with script tags.

The following code successfully retrieves CSS links:

foreach (var c in HeadElement.Controls)
{
    var link = c as HtmlLink;
    if (link != null)
    {
        var url = new Uri(link.Href, UriKind.RelativeOrAbsolute);
        if (url.IsAbsoluteUri == false)
        {
            System.Diagnostics.Debug.WriteLine(url);
        }
    }
}

However, I have noticed that script tags are not present in the control collection, and they cannot be found in the ScriptManager.GetCurrent(Page) Script collection either (which seems to fetch the AjaxControlToolkit ScriptManager).

If anyone has any suggestions or tips, I would greatly appreciate it!

Just to clarify, the script tags on the master page are standard, not added dynamically or via a script manager.

Here is an example of the HTML Markup:

<head id="HeadElement" runat="server">
   ...
   <link href="/css/normalize.css" rel="stylesheet" />
   <link href="css/jquery.ui.timepicker.css" rel="stylesheet" />
   ...
   <script src="/Scripts/bowser.js" type="text/javascript"></script>
   ...
</head>

Answer №1

Solution to the query:

It is not possible in WebForms to parse script tags into control objects without including runat="server" within them.

Solution to the issue at hand:

We encountered problems with caching, where clients were not receiving updates when a new version of the site was deployed.

In our MVC setup, we utilize bundles which automatically incorporate version URL parameters to ensure clients fetch the most recent version. However, in our older WebForms application, script and link tags are scattered all over. I considered implementing something akin to bundling through the Master Page.

Upon further investigation, the problem was easily solved by inserting the following snippet into the web.config file:

<system.webServer>
    <staticContent>
        <clientCache cacheControlMode="UseMaxAge" cacheControlMaxAge="00:20:00" />
    </staticContent>
</system.webServer>

The cache duration was set to 20 minutes, matching our default session timeout period. This ensures users experience optimal performance throughout their sessions (reducing the need for browser requests).

Post implementation, browsers will request updated content from the server - with IIS handling responses efficiently using 304 not modified if necessary, thus minimizing bandwidth consumption.

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

Different Angular 2 components are resolved by routes

Consider this scenario: Upon navigating to the URL /product/123, the goal is to display the ProductComponent. This is how it's currently configured: RouterModule.forRoot([ { path: 'product/:productId', ...

Import data from JSON using JavaScript

I have a collection of txt files that contain custom content. The file names are stored in a JSON array. { txtFiles: ['./file1.txt', './file2.txt', './file3.txt'] } I am looking to use the require function in JavaScript t ...

Showcasing a graphical representation with the help of Highcharts

I am currently exploring JavaScript and trying to familiarize myself with interactive charts using the HighCharts library. Unfortunately, I have been facing some challenges in getting the graph to print correctly. Despite attempting various examples, none ...

Dynamic dropdown menu that includes client-side filtering functionality

Does anyone know of an ajax control that meets the following criteria: Enables users to type in for auto-suggestions Dropdown only displays values starting with the characters typed One postback is needed to fetch all data on initial key-in, then f ...

JQuery grid pagination bar mysteriously missing

I'm having an issue with a Jquery grid that is built on an HTML table. I've properly configured the grid properties, including implementing pager functionality with a page size of 10. However, I am unable to see the page up and page down buttons ...

Having a tough time getting Storybook up and running

Hey there, I'm new to exploring React and I decided to give Storybook a try. Unfortunately, I encountered an error when attempting to run Storybook. I attempted to resolve the issue by updating with npm update, suspecting there may be dependency confl ...

Guide to effectively utilizing jQuery Deferred within a loop

I have been working on a function that needs to loop through a dataset, updating values as it goes along using data from an asynchronous function. It is crucial for me to know when this function finishes running the loop and completes all updates. Here is ...

The latest error in the Next.js 13 app directory: React child is not valid (detected: [object Promise])

I am currently utilizing the new app directory feature in Next.js 13. Within my project, I have a page component located at app/page.tsx. This component contains the following code snippet: "use client"; import { useState } from "react" ...

Building a custom WebRTC Unity to JavaScript client for one-way video streaming within the local network

In this project, Unity is used to capture video and it communicates with JavaScript via WebRTC. Despite successful communication between the two clients, the JavaScript client is unable to display any video from the Unity client. The issue of no video out ...

Running a designated AJAX function from a variable by utilizing Applescript

Struggling to execute a JavaScript code within a page using Applescript. In the JavaScript, an AJAX function was defined like so: var myFunction = function () { // Here be the code... } I attempted this in Applescript: do JavaScript "document.myFunct ...

JQuery: The .not() function does not effectively filter out items from the collection

I want to iterate through multiple span elements and extract the text from them. However, I need to skip any text that is within elements with a specific class. Here's an example: <html> <head> <script src="http://code.jquer ...

Difficulty switching back and forth between three varying heights

I have a container with a button labeled "Show more". Upon clicking the button, the height of the container will transition through 3 different states. <div class="segment-suggestion-content height-small"> <div class="segment-suggestion-sh ...

Use jQuery to set the onclick attribute for all elements rather than relying on inline JavaScript

I am currently facing a challenge with converting inline JS to jQuery. My goal is to eliminate all inline onclick events and instead target them by class. HTML - checkbox <td class="center"> <?php if ($product['selected']) { ?> ...

Journeying through JSON: Presenting the value alongside its hierarchical parent

I'm completely new to JSON Path, so I'm not sure how complicated this could be, or if it's even possible. The JSON structure I have consists of multiple groups, each containing a set of fields. Both the groups and the fields have their own ...

Integrate data from Firebase into a React-Table component

I am currently working on a table component that fetches data from Firebase to populate three fields: Name Date Comment For each entry, I want to add a new row. The pivot has been successfully added. However, when trying to populate the table, I am encou ...

Uploading Files with PhoneGap using Ajax

I have been attempting to execute this PhoneGap example for uploading images from a device to a server. // Wait for PhoneGap to load // document.addEventListener("deviceready", onDeviceReady, false); // PhoneGap is ready // functi ...

What could be causing my jQuery handler to not capture my form submission?

I am developing a Ruby web application and using JQuery and AJAX to send/receive data. However, I am facing an issue where pressing the enter key does not submit the form. What should I do to ensure that my form submits successfully? Within my Foundation ...

Where is the most appropriate location to implement a try-catch block for a simple division method?

Here is the code snippet I've been working on: using System; using System.Data; using System.Transactions; namespace BasicCourse.Exceptions { class Program { static void Main(string[] args) { Division ...

What is the best way to locate the position of a different element within ReactJS?

Within my parent element, I have two child elements. The second child has the capability to be dragged into the first child. Upon successful drag and drop into the first child, a callback function will be triggered. What is the best way for me to determi ...

Resources for Vue.js stylesheets

Vue.js is my latest discovery and I have been experimenting with the single file component architecture. A small issue I encountered was that all of my components' styles were being loaded on the page, even if they weren't currently active. Is t ...