Is it possible to export a webpage while maintaining relative paths for CSS, images, and other assets?

I am currently working on a large enterprise web application and have created a basic prototype HTML page. This page consists of a list of CSS and JS includes with minimal markup. Surprisingly, there are a total of 57 CSS includes and 271 javascript includes in this simple prototype (sounds crazy, right?).

When this project goes into production, the CSS/JS files will be minified and combined in different ways. However, for development purposes, I have left them as is.

The HTML file is being served by a straightforward Apache HTTP server and accessed through a URL like http://localhost/demo.html. Please note that access to this link requires being behind the firewall.

I want to bundle up this single HTML file along with all referenced JS and CSS files into a ZIP archive to easily share it with others. The idea is to allow recipients to simply unzip the file and directly open the HTML file.

I am facing two main challenges:

  • The CSS files reference images using non-relative URLs such as url(/path/to/image.png), which would break when viewing the HTML after unzipping.
  • There are numerous other JS/CSS files and images in the same folders, even though the demo does not use all of them. Including the entire folder in the zip file would make it unnecessarily large.

As someone who regularly creates these kinds of demos, I am looking for an easy solution to create a ZIP file that:

  1. Updates the CSS files to use relative URLs instead of absolute ones
  2. Includes only the JS/CSS files referenced by the HTML, as well as the specific images used in those CSS files

If I could automate this process without manual intervention, it would be amazing!

For example, one of the CSS files has the following path and filename:

/ui/demoapp/css/theme.css

This CSS file contains image references like:

url(/ui/common/img/background.png)

To make this work, the relative image path should look something like this:

url(../../common/img/background.png)

Answer №1

After facing this challenge head-on, I decided to take matters into my own hands and find a solution that suited my specific needs. Through some trial and error, I discovered two options that proved to be quite helpful:

  1. I realized that modern browsers offer a convenient "Save Page As..." feature located under the File menu, or within Chrome's dropdown menu. However, this method isn't always foolproof, especially with pages generated by javascript.

  2. To address this issue, I took it upon myself to develop a custom application capable of extracting all CSS and Javascript resources while converting CSS references to relative URLs. Although effective for me, this might not be the ideal solution for everyone else.

If there are any individuals familiar with a more user-friendly utility or alternative to the browser's native "Save page as..." function, please don't hesitate to share your insights in a separate response.

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

React is not applying the font as expected

Currently, I am working on setting up a @font-face in my index.css file: @font-face { font-family: "Raleway"; src: url(../assets/fonts/Raleway/Raleway-VariableFont_wght.ttf) format(truetype), } Next, I am trying to apply this font family ...

Determining the file size of an HTML and JavaScript webpage using JavaScript

Is there a way to determine the amount of bytes downloaded by the browser on an HTML+JS+CSS page with a set size during page load? I am looking for this information in order to display a meaningful progress bar to the user, where the progress advances bas ...

Tips for aligning multiple buttons to one side of a row using CSS in Bootstrap

I am currently working on a project that involves creating a row with columns. The left-hand side column contains the name, while the right-hand side is populated with three buttons. However, I am facing some challenges in properly aligning and spacing out ...

HTML and CSS site lacking responsiveness

I am new to HTML and I have created a page that looks good on desktop, but it is not responsive on mobile devices. Can someone please help me with my HTML and CSS code? .link-menu { color: black; } .topbar-p ...

The PHP Admin Panel conveniently shows the Edit post form right at the bottom of the page

After following a PHP CMS tutorial, I created this awesome website for a school. It's my first dynamic website, and I even managed to create an admin panel that looks like this. Admin Panel Pretty cool, right? Initially, I followed a basic tutorial ...

Adjusting the box sizing of a contentEditable DIV to conceal the first and last characters

I am having trouble with a ContentEditable div that requires the hiding of characters, specifically the first and last character. I need to overlay a layer on top of the "#" character to make it appear as if the character and the border line beneath it are ...

Show the name of the current user in a WordPress form using a readonly input field

How can I display the logged-in WordPress username (display name) in a form input field that is set to readonly? I have already checked out the Function Reference/wp get current user, but haven't had any success with it. Take a look at the code snip ...

How to Change Background Color to Black for a PNG Image Using CSS in Ionic

When applying CSS in Ionic, I encountered an issue with the background image causing the background to turn black. Without the image, everything looks fine. ion-content { --background: url("/assets/product_background.png") 0 0/100% 95% no-re ...

The Joys of Delayed Animation with jQuery Isotope

Has anyone successfully modified the CSS3 transitions in jquery Isotope to incorporate a delay for shuffling items, such as using "transition-delay: 0s, 1s;"? I am aiming for a specific shuffle direction - first left, then down - to create a more calculat ...

Locate the selected icon on one webpage and automate the clicking of a similar icon on a different webpage using Python and Selenium

I've exhausted all my resources and searched extensively online, but I still can't find a viable solution to my current dilemma. Any assistance in helping me navigate through this challenging situation would be greatly appreciated. (If possible, ...

Create numerous collapsible elements using the ui.bootstrap and AngularJS frameworks

Currently, I am working on implementing the ui bootstrap collapse feature. The static single or double collapse system works perfectly fine, but for my specific design requirements, I need to create collapses using ng-repeat. Unfortunately, I am unsure how ...

Enhancing a video tag with a mysterious dark mask

I'm looking for a way to darken a video in my hero section to make it easier to see the white menu items that are getting lost in the brightness. Any tips on how to achieve this using CSS or Bootstrap? <template> <section class="se ...

Optimal method for integrating Google Font in GWT application

After successfully installing the Roboto font on my machine, I proceeded to include it in my welcome.html file by adding the following code: <link href='http://fonts.googleapis.com/css?family=Roboto:regular,medium,bold,thin' rel='stylesh ...

Tips for accessing a URL with a specific value in the HTML file

This form submits a URL in this format: <form action="search.php?search=" method="GET" id="search-form"> <input id="search-text" name="search" type="text" maxlength="30" placeholder="type keyword"/> <button type="submit" name ...

Is it Possible to Load Images Without Using Javascript?

When I hover over certain links on my HTML pages, large images are displayed but take a while to load. I prefer not to use JavaScript to preload the images. Are there any alternative solutions available? ...

Ensure that the divs are properly aligned with the paragraphs

I received assistance previously, and I am seeking additional help in maintaining the position or adjusting the size of elements to fit different window viewport sizes such as tablets, mobile devices, or varying monitor sizes while keeping the appearance c ...

Discover the ins and outs of the "DOM" within a string, treating it as HTML in AngularJS

Looking to extract data from a legal HTML string based on tags and attributes, but want to avoid using jQuery in favor of Angular. Are there built-in functions in Angular for this task? ...

When I click on the icon, I wish for it to revert back to its original state by spinning

Is there a way to revert the icons back to their original state when clicked again, without losing any of the current functionalities? When an icon is clicked for the first time, it rotates 180 degrees. The icon rotates back if another icon is clicke ...

Creating a dynamic and adaptive layout using Bootstrap 4

Currently, this webpage appears as follows: I attempted to organize the images in row 2 of the grid but the outcome was reversed Upon resizing to a mobile screen and switching to a flex column layout: I tried to address the overflow issue The HTML code: ...

Does IE8 only submit form data when a button is clicked, not when the submit

Something odd is happening - I had this working perfectly around a month ago, before making several code updates. Now, the live submit handler isn't triggering in IE8. However, it does work when triggered by a button click. Take a look at the code sni ...