The issue of Ejs partial header and footer file only functioning in one file and not the other (both at the same directory level)

I'm in the process of setting up a view page for a post on the main page of a website. Both pages share the same header and footer files, located at the same directory level. However, while one page is functioning correctly, the other is not. The errors being displayed seem to be related to the script and link tags within the header and footer files.

Error details: (custom scripts and links are also causing these issues)

5ab70c4e84fa1b212efa0145:5 GET http://localhost:5000/home/scripts/lib/jquery-3.3.1.min.js net::ERR_ABORTED 5ab70c4e84fa1b212efa0145:1

Refused to execute script from 'http://localhost:5000/home/scripts/lib/jquery-3.3.1.min.js' because its MIME type ('text/html') is not executable, and strict MIME type checking is enabled.

5ab70c4e84fa1b212efa0145:1 Refused to apply style from 'http://localhost:5000/home/stylesheets/main.css' because its MIME type ('text/html') is not a supported stylesheet MIME type, and strict MIME checking is enabled.

The code for my header and footer partials are as follows:

Header:

<!DOCTYPE>
<html>
    <head>

        <script type="text/javascript" src="scripts/lib/jquery-3.3.1.min.js"></script>
        <script type="text/javascript" src="scripts/lib/bootstrap.min.js"></script>
        <link type="text/css" rel="stylesheet" href="stylesheets/bootstrap.min.css">

        <script defer src="https://use.fontawesome.com/releases/v5.0.8/js/all.js" integrity="sha384-SlE991lGASHoBfWbelyBPLsUlwY1GwNDJo3jSJO04KZ33K2bwfV9YBauFfnzvynJ" crossorigin="anonymous"></script>

        <link type="text/css" rel="stylesheet" href="stylesheets/main.css">

    </head>
    <body>
        <nav class="navbar navbar-default navbar-inverse">
            <div class="container-fluid">
            <!-- Brand and toggle get grouped for better mobile display -->
                <div class="navbar-header">
                    <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" aria-expanded="false">
                    <span class="sr-only">Toggle navigation</span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                    </button>
                  <a class="navbar-brand" href="/"><i class="far fa-heart"></i> The Beanie Boo Network</a>
                </div>

                <!-- Collect the nav links, forms, and other content for toggling -->
                <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">

                  <form class="navbar-form navbar-left">
                    <div class="form-group">
                      <input type="text" class="form-control" placeholder="Search">
                    </div>
                    <button type="submit" class="btn btn-default">Submit</button>
                  </form>
                  <ul class="nav navbar-nav navbar-right">
                    <% if(!currentUser){ %>
                        <li><a href="/login">Login</a></li>
                        <li><a href="/register">Register</a></li>
                    <% } else { %>
                        <li><a href="#"><%=currentUser.username%></a></li>
                        <li><a href="/logout">Logout</a></li>
                    <% } %>    
                  </ul>
                </div><!-- /.navbar-collapse -->
              </div><!-- /.container-fluid -->
            </nav>

        <div class="container">

Footer:

</div>
    <script type="text/javascript" src="scripts/main.js"></script>
    </body>
</html>

Working file content: (full)

<% include ../partials/header %>

    <header class="jumbotron">
        <div>
            <h1>Beanie Booboard</h1>
            <h4>Keep up to date with whats going on on The Beanie Boo Network</h4>
        </div>
    </header>

    <% posts.forEach(function(post){ %>
        <div class="thumbnail">
            <div class="row">
                <div class="caption col-sm-6">
                    <div class="container">
                        <h2><%=post.title%></h2>
                        <p><%=post.content.substring(0, 50)%>...</p>
                        <p><em><%=post.author%></em></p>
                        <p><%=post.created.toDateString()%></p>
                        <a href="/home/<%=post._id%>"class="btn btn-xs btn-danger">Read More</a>
                    </div>
                </div>
                <div class="thumbnail-img col-sm-6">
                    <img class="img-responsive" src="<%=post.image%>">
                </div>
            </div>
        </div>
    <% }); %>

<% include ../partials/footer %>

Non-working file content: (full)

<% include ../partials/header %>


<% include ../partials/footer %>

I am trying to understand why one file is encountering errors while the other is not, how I can prevent this issue in the future, and how to resolve it should it occur again?

Answer №1

Consider incorporating <%- include(“partials/header”); -%> into your header section And <%- include(“partials/footer”); -%> for the footer content

Answer №2

Resolution:

The resolution to this issue may seem peculiar as it fails to provide a clear reason why the functionality worked on one page and not the other. However, I made slight modifications to the script and link tags. By removing the type attribute from both the link and script tags in the header and footer files, and adding "/" before the file paths, the problem was resolved. The page that was already functional remained unchanged, while the previously malfunctioning page now works seamlessly.

If anyone can shed light on the underlying reasons for this discrepancy, I would greatly appreciate an explanation. Thank you.

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

What is the best way to eliminate excess elements from overflow:hidden?

Whenever I click on a modal, it changes my body to overflow:hidden. As a result, the scrollbar disappears and my page becomes unscrollable. Once I close the modal, my body reverts back to overflow:auto allowing the page to scroll again. These functionaliti ...

Adding a specialized loader to vue-loader causes issues when the template contains personalized elements

My vue2 component is structured as follows: <template> <p>Hello world</p> </template> <script> export default { name: 'Example' }; </script> <docs> Some documentation... </docs> In addition, I& ...

Tips on displaying text inside an icon

As a self-taught newcomer to web development, I apologize if this is a basic question. I'm trying to figure out how to display text inside an icon, like putting a number inside a heart. Would using a webfont icon not be suitable for this purpose? Is ...

Adjust the top margin of content to account for the height of a fixed header

When dealing with a fixed header that has been removed from the HTML flow, it can be tricky to adjust the content below it. The challenge arises because the height of the header can vary based on screen size. How can we dynamically adjust the margin-top fo ...

Issue with state change in Component (React with Redux)

I am another person facing a similar issue. I have been unable to identify the error in my code yet. I suspect it has something to do with mutation, but despite trying almost everything, I am at a loss. My component does not update when I add new items to ...

Angular JS is experiencing issues with two modules not functioning properly on a single page

Angular JS is a new technology for me. I have two modules, first2a and first22. Each module contains a controller named model1 and model2. Here is the HTML code: <!DOCTYPE html> <html > <head> <link rel="icon" ...

Adding a button in Node and Mongoose for updating data: A step-by-step guide

I have set up a mongoose database containing events, each event is displayed within a bootstrap card. My challenge now is to find a way to redirect the admin to a page where they can update the event card and save it to my mongoose db. The problem I' ...

Verify the ability to view a webpage

I am currently working on creating a method to check if data access is equal to next.data.access. Since it's an array, I cannot use the includes method. It would be enough for just one of the data access values in the array to return true. auth.guard ...

Ensure the filelist resets each time the bootstrap-modal is hidden or closed

Context I am in the process of developing a form where users can input data and upload an image file. The information entered into the form, along with the file name, is stored in a MySQL database. To style the website, I am utilizing Bootstrap. When a u ...

What is the best way to set a value for a variable within a UI component in React?

I'm still learning the ropes with React and JavaScript. My current challenge involves declaring a temporary variable and assigning the value of companyData.name to it, as I need to gather data from two variables like companyData.name. Below is my cod ...

What is the best way to trigger the scrollTo function after the list (ul) with images has finished reflowing?

In my React application, I used the Material-UI List component to display images with varying dimensions and limited to a max-width of 25%. Upon loading the page, I call scrollTo({top: some-list-top-value}) on the list to position it at a specific point. ...

Generating custom-styled entries using Word VBA

I have set up styles in my Word document, such as My_Style (which I use for titles). I am looking to create entries for illustrations that correspond to the number from that particular style. Here is the code snippet I am using: Sub Macro4() ' &apos ...

Obtaining Relative Values within Every Iteration using jQuery

I'm currently facing an issue with retrieving relative values within a .each() loop using jQuery. I have a set of table rows that contain a text input and a radio button each. My objective is to iterate through each row and save the value of the text ...

A perfectly organized and justified menu with evenly spaced horizontal list items

I couldn't find a solution to evenly spacing out a series of list items for a menu styled list. After realizing CSS alone wasn't enough, I decided to incorporate some javascript (jQuery). My goal was to have equal padding between each LI without ...

Transfer information from my class to a specific pathway

Currently, I am in the process of developing an application using Angular 2. My goal is to be able to send data from my class to a specific route within the application. Sample Code @RouteConfig([ { name: 'Slider', ...

Erase blob_over from the Wordpress menu hover effect

I've created a unique style for the Donate button on this website, but I'm struggling to remove the hover effect. Any suggestions on where to start? Website URL: This is my Custom Class CSS: .donate { background:#4A1383; padding:0px 10px 0px 1 ...

issue with useReducer not functioning as expected

I encountered an issue with my customized Select component. It includes a select and options while listening for onChange events. Additionally, I am using a useReducer function that initializes some variables. However, even after selecting an option, the s ...

Validating date inputs with ng-change in AngularJS

I am currently utilizing AngularJS along with AngularJS bootstrap within my webpage. One of the components I have is a date picker directive that is structured like this: <div class="form-group {{dateStatus.class}}"> <p class="input-g ...

Changing date and time into milliseconds within AngularJS

Today's date is: var timeFormat = 'dd MMM, yyyy hh:mm:ss a'; var todayDate = dateFormat(new Date(), timeFormat); Can we convert today's date to milliseconds using AngularJS? Alternatively, how can we use the JavaScript function getT ...

Using an icon font as a background in CSS attribute

I am struggling to replace a background image in CSS with an icon font instead of an icon image. I have been unable to accomplish this task. Here is the CSS property I am working with: .social-networks .twitter{background:url(../images/social/twitter.png) ...