The addition of the URL # fragment feature to Safari's browser caching system

Currently, I am focused on improving the speed of our website. To achieve this, the client is utilizing ajax to preload the expected next page of the application:

$.ajax({url: '/some/real/path', ...});

Upon receiving a response from the server with the header:

Cache-Control => 'max-age=20'

This indicates that the response is cacheable.

The clientside application then waits for confirmation before transitioning the browser to the predicted page. This transition includes adding additional information in the URL as a # fragment, which can only be obtained once the user has taken action:

location.href = '/some/real/path#additionalInfoInFragment';

Upon transitioning to the page, the additional info in the fragment is utilized by the page's javascript to produce a specific effect.

Most browsers successfully insert the initial ajax request response into their cache and retrieve it when transitioning using location.href. This process saves on server requests and speeds up the loading time.

However, Safari seems to encounter issues with caching due to the '#additionalInfoInFragment' part of the transition. The fragment is included in Safari's cache key, affecting its ability to retrieve cached content. Entries from Safari's cache.db file further highlight this issue:

* ajax request: INSERT INTO "cfurl_cache_response" VALUES(3260,0,-1982644086,0,'http://localhost:8080/TomcatScratchPad/EmptyPage','2012-05-14 07:01:10');

* location.href transition: INSERT INTO "cfurl_cache_response" VALUES(3276,0,-230554366,0,'http://localhost:8080/TomcatScratchPad/EmptyPage#wtf','2012-05-14 07:01:20');

It is worth noting that Chrome behaves correctly in this scenario, despite similarities in WebKit code with Safari.

Your input and ideas from the community would be greatly appreciated. Thank you!

Answer №1

There are only a few choices available:

  1. Submit a bug report to Apple and let it go. :-) Your caching mechanisms will still function with other browsers. In general, Safari has a very small market share, unless your website is specifically aimed at (for example) iPad or iPhone users - in which case the statistics for your site may vary. :-) (You likely know from your logs how many Safari users visit your site.)

    Alternative: If Safari is a significant portion of your target audience and this issue truly bothers you, check if it's a bug within any of its open source components, and if so, consider providing a fix.

  2. Avoid using the fragment identifier to transmit information, use an alternative method (such as a cookie) instead.

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

Images are failing to load in Ionic 3

Currently working on developing an Ionic application and troubleshooting the use of the camera native plugin. The script functions flawlessly in a fresh project, but encounters issues within the current project environment. Initially suspected a problem w ...

Adjust the div class to align with its content

I am looking to modify the code in order to copy the text of a div to its own class. Currently, the code provided copies text from all sibling div elements, but I specifically want each individual div's text to be its own class. For example, with the ...

When viewing on mobile devices, the hover effect in responsive web design

While working on a responsive website, I encountered some challenges. I have a Div containing an image and some information. When a user hovers over this div, the background changes and 3 buttons appear. However, the issue arises when using a mobile devi ...

Creating a stunning display of six video textures on a cube through the power of three.js

My current project involves working with a video that has been segmented into six parts. Here is a screenshot of the input video. The goal is to project these 6 videos onto the six faces of a cube using JavaScript: <!DOCTYPE html> <html> &l ...

Creating a JSON array in JavaScript for future reference

I am interested in creating a JSON array where I can define the fields and add data to it later in my code. However, I am unsure about the correct syntax to achieve this. So far, my attempts have resulted in some parse errors; <script> var myJSONAr ...

Creating a new form upon clicking

By clicking the "Add New Job" link, a new form with three fields will appear. This is the primary form: <h2>JOB EXPERIENCE 1</h2> <div class="job-content"> <input type="text" value="Company" name="company" /> <input type="te ...

Tips for initiating a component within a loop and terminating it after completing all 3 iterations

Looking for a solution to open and close tags in a loop every 3 iterations. The objective is to create a grid using container, row, and column elements. However, I am unsure how to achieve this. Example: render(){ const arrayName = ["john", " ...

Utilize JavaScript declarations on dynamically added strings during Ajax loading

Is there a way to append HTML strings to the page while ensuring that JavaScript functions and definitions are applied correctly? I have encountered a confusing issue where I have multiple HTML elements that need to be interpreted by JavaScript. Take, for ...

Toggle WooCommerce Shipping Costs Using Radio Buttons

I've been struggling to find a solution for this issue. I am attempting to display or hide specific shipping rates depending on a radio button selection on the Woocommerce checkout page. However, I lack the knowledge of Ajax and JQuery required to imp ...

Dynamic Visibility Control of GridPanel Header in ExtJS

I have a GridPanel that needs to display a limited number of resources. If there are more resources available than what is currently shown, I would like the panel's header/title to indicate this by displaying text such as "more items available - displ ...

The function inArray() in jQuery will return a value of -1 when an array consists of

When using jQuery inArray, if the array contains only one element, it will return -1. var a = Array(1); console.log($.inArray(1,a)); This result is -1. However, if the array has 2 or more elements, it functions correctly. var a = Array(1,2,3); console.l ...

Avoiding the creation of a history entry while switching languages on a Next.js website

I'm currently developing a Next.js project that includes a language dropdown feature for users to choose their preferred language. In the existing setup, we are utilizing the router.push method from next/router to update the language selection and red ...

Getter and Setter Implementation in Typescript without Using Classes

Check out these various SO questions discussing Typescript getters/setters: from 2015, Jan 2018, Sept 2018, and more. Now, the question arises - what is the best approach to define Typescript types for getters/setters in a plain JavaScript object without ...

Stop Rails application from inadvertently responding to AJAX requests made by jQuery

Having developed a rather intricate Rails (2.3.8) application with plenty of jQuery ajax requests, I find myself facing an intermittent bug that is quite challenging to reproduce. Occasionally, a jQuery $.ajax({..}) request will attempt to access a page it ...

Passing data between the view and JavaScript in a Django application

Initially, I pass a JavaScript variable 'confirmed' to my Django view using a POST request. Then, a Python script processes this variable to perform certain actions. Finally, I aim to pass the processed data back to my HTML/JavaScript for display ...

What is the best way to enable the delete function exclusively for users who are logged in?

I am currently working on implementing a delete function in JavaScript that will remove a MySQL row if and only if it was created by the user who is currently logged in. This means that users cannot delete rows they did not create. Below is the progress I ...

Function activation in Element requires a double click to initiate

I've encountered an issue with a web element I'm working on where the click function only triggers after the first click, rendering the initial click ineffective. Here's the code snippet in question: HTML: <div> <a href="#0" cla ...

Retrieve a result by utilizing a nested function in conjunction with the request NPM module

Hello there! I'm currently working on scraping data from the ghost blogging platform using the request package. However, I've run into a bit of a roadblock when trying to return a value of a nested request. I've pinpointed the area that seem ...

Requesting data using Ajax with multiple parameters

I have an ajax call that requires adding multiple sets of data. function sssssss(page){ loading_show(); var form2 = document.myform2; var dataString1 = $(form2).serialize(); ...

Creating dynamic selection options in an HTML select tag using PHP

When retrieving category and sub-category information from an API json file, the API returns category objects with a "parent" attribute. Main category objects have a parent attribute equal to 0, and sub-category objects have the parent attribute equal to t ...