Troubleshooting a relative path problem in an EJS style tag

Seems like there's a simple issue here that I can't quite figure out.

In my node application, I have a layout.ejs file that includes a script tag:

For example:

<link href="css/main-theme.css" rel="stylesheet">

However, when I visit a restful route for a "blog post," such as posts/:someId

the stylesheet is now trying to locate itself at this path -> "posts/css/main-theme.css".

How can I make sure that style and script tags search for their sources using the same path regardless of the current URL route?

Answer №1

Insert / in front of the path to make it like this

<link href="/css/main-theme.css" rel="stylesheet">

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

Adding a stylish background image to a header

Recently, I tried to add a background image as a backdrop for my Header but ran into some issues. I was successful using a background color, but not with the background image itself. h2 { background-color: red; font-family: "Comic Sans MS", cursiv ...

Using If-Else Statements in HTML to Showcase Information

I need assistance with passing the alt text value on an image using the following code: <img *ngIf="document.story_image_1 " [src]="document.story_image_1 " class="image-1" alt="{{document.image_alttxt | 'default ...

Tips for utilizing loops in Node.js to store form data as objects and arrays of objects in MongoDB

Having recently started working with MongoDB, I am incorporating Node.js, Express 4, and mongoose (mongoDB) into my project. I am facing an issue when trying to save form data to mongoDB within a loop, especially because my model contains both objects and ...

Utilize Google Console with Chrome and jQuery to extract the name and URL from HTML content

I am trying to parse the HTML source code in order to extract all links and text from it, and then store this information in a multidimensional array, all within the Google Chrome console. Here's a snippet of the code that needs to be repeated 10 tim ...

creating a modal form with dynamic content

I am working on a Django template that shows a list of items from a database. My goal is to be able to edit or update each item when clicked. I have managed to display the items I want to update, but I'm encountering an issue. The problem I'm fac ...

Iterating through the startPrivateConversation method in Botkit for a multitude of users

In order to send an update to all my users, I created a new bot controller in a separate js file. To achieve this successfully, I needed to implement a notification function inside the controller's rtm_open function. The goal was to iterate through th ...

Numerous occurrences of Node Webkit (nwjs) are able to exchange cookies

Currently, I am facing an issue where two nwjs apps are running in different executables, but their cookies are being stored in the same folder C:\Users\Nickname\AppData\Local\node-webkit. This means that the cookies from one app c ...

What is the reason for the addEventListener function not being able to access global variables?

I have set up an event listener function to utilize popcorn.js for displaying subtitles. Additionally, I have created functions that are unrelated to popcorn.js outside of the event listener and declared a global variable array. However, when attempting ...

I am having trouble accessing a font stored locally using @font-face in React with CSS

Having some trouble loading the "Inspiration-Regular.tff" font from theme.js. The URL is accurate and there are no issues there. In line 137 of the code, I am setting "Inspiration-Regular.tff" as the body's font-family, but despite the element showi ...

Unable to retrieve information from the HTML form and pass it to the PHP script

I've got this code snippet in my index.html file: <html> <head> <title>Login</title> </head> <body> <h2>Admin Panel</h2> <FORM NAME ="form1" METHOD ="POST" ACTION = "login.php"> <INPUT TYPE = ...

The webpage appears fine on the local server, but displays incorrectly on IIS (Internet Explorer 11)

My project looks great when I run it locally on my computer and open the page in Internet Explorer 11: https://i.stack.imgur.com/yZvo2.png However, when I deploy the page to an IIS server and navigate to the page, it appears differently in Internet Explo ...

Sending chosen choice to controller method

I'm working with a table that contains inputs and angular models. <td> <select class="form-control" id=""> <option ng-model="mfrNo" ng-repe ...

Using Ubuntu, AWS EC2 Instance unable to start Node.JS Express App

For the past 24 hours, I have been struggling to get my express app up and running. Despite following tutorials and reinstalling everything, I still can't seem to make it work. If you're curious about the M.E.A.N stack installation process that ...

Ways to stop CKEDITOR from automatically saving textarea or contenteditable content

I've integrated the CKEDITOR plugin for a format toolbar feature on my web application. It seems that the message shown above is a default one provided by CKEDITOR. My goal is to have users start with a blank textarea every time they visit the page, ...

Accessing JavaScript file on various endpoints

Currently, I am developing a large javascript application which functions as a single page application. My technology stack includes node.js with jade. I have some concerns regarding the loading of javascript files for the front end. Let's say we hav ...

Utilizing Cross-Domain Cookies in AngularJS, Node.js, Express.js, express-session, and Mongo Store

I am in the process of creating a unified login/authentication service for a suite of programs within the same company. The concept is centered around micro-services, with one dedicated service managing authentication and maintaining it across all programs ...

Using Jquery to update the information displayed in a div class to show more details about the clicked video

I am currently developing a video playlist similar to YouTube for my hybrid app. I am fetching and displaying the data using functions from json data provided by the web server. Below is a sample of the json data: [{"video_id":"1","video_youtube_title":" ...

Sending error messages from server to client (leveraging Express and Backbone)

I'm struggling with passing server error messages to a client after thrashing around for a while. Here's what I have on the server side (simplified): export function get(req: express.ExpressServerRequest, res: express.ExpressServerResponse) { ...

Align dropdown navigation menu/sorting dropdown in the same position as the button

Exploring the world of dropdown menus in CSS has led me to encounter some challenges. I am striving to ensure that the dropdown boxes appear on the same line as the button that triggers them. Below is the CSS code I have been working with: /* global style ...

Struggling to have PHP process and store form data in MySQL database

I am attempting to process HTML form data into a MySQL database using PHP for the first time, and I am feeling overwhelmed. The form is POSTed to the formSubmit.php file, where the variables are created for the SQL command to query. I have tried adjusting ...