Is there a way to ensure that Jade automatically updates the HTML template when the linked CSS file is modified, using livereload and Grunt?

Currently, I am in the process of setting up Grunt to ensure that whenever a linked .css file undergoes a change, the jade template which is linked to the .css file also automatically reloads. However, I am facing challenges with compiling my jade templates due to the fact that the template in question formats a response from an API. Thus, unless there are modifications made to the .jade file, the .css file does not get pulled in again. While I can manually refresh the page to view the style changes, my aim is to automate this process.

As of now, if I make changes to a .jade file, the specific .jade file reloads and I can instantly see the changes in my browser. On the other hand, if I modify a .css file, grunt detects it and reloads the .css file. Nevertheless, since the .jade file has already been converted into .html, the styling does not update accordingly.

EDIT: Upon further investigation, I have discovered that only Jade files which format data from API calls are impacted by this issue. On the contrary, Jade files formatting static data are able to update correctly with Livereload when .css files are changed.

Below you will find my Gruntfile.js configuration and the specific Jade template that I am working with.

module.exports = function(grunt) {

grunt.initConfig({
    concat: {
        dist: {
            src: ['main.js']
        }
    },
    watch: {
        options: {
            livereload:true
        },
        css: {
            files: ['public/css/*.css'],
            options: {
            }
        },
        js: {
            files: ['routes/**/*.js', 'main.js', 'Gruntfile.js'],
            options: {
            }
        },
        jade: {
            files: ['views/**/*.jade'],
            options: {
                spawn: true
            }
        }
    },
    express: {
        dev: {
          options: {
              script: 'main.js'
          }
        }
    }
});

grunt.loadNpmTasks('grunt-contrib-concat');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-express-server');
grunt.registerTask('server',['express', 'watch']);
grunt.registerTask('default', ['server']);

};

The Jade Template:

    doctype html
    html(lang="en")
        head
            link(rel='stylesheet', href='http://localhost:9000/css/search.css')
            link(rel='stylesheet', href='http://fonts.googleapis.com/css?family=Roboto')

    title= pageTitle

    body

    h1 Here are your results!

    ul.products
        each item, index in items
            li
                a(href=item.viewItemURL)
                    img(src=item.galleryURL)
                    p=item.title
                    -var currentPrice = Number(item.sellingStatus[0].currentPrice[0].__value__);
                    p.price $#{currentPrice.toFixed(2)}

Answer №1

Experiment with using css paths within jade templates

watch: {
    ...
    jade: {
        files: ['views/**/*.jade', 'public/css/*.css'],
        options: {
            spawn: true
        }
    }
},

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

await/async: challenge with conditional statements in the compiler

Utilizing async/await within a web application to retrieve data from a database and use it for other queries. Here is the function being used: exports.getByUserAndPurposeForService = async (req, res, next) => { var serviceID = await Service.getId ...

What is the best way to send data from client-side JavaScript to node.js using XMLHttpRequest?

I have some HTML input fields in my index.html file. <input type="text" id="handle" > <input type="text" id="message" > <button id="send">send</button> After filling in the information and clicking "send", I want to pass this data ...

Misplaced Bootstrap 4 tooltip causing alignment issues

Hello, I've encountered an issue while using Bootstrap 4 and have compiled the CSS from the Sass files using Ruby Sass 3.7.4. Although I removed certain parts of the Sass, I don't believe there are any dependencies affecting how Tooltips functio ...

Adjust the background color of a non-selected Material-UI checkbox

Currently, I am working with a combination of React-Redux and Material-UI to style my project. Within this setup, I have a checkbox component that is placed on a toolbar with a blue background color (#295ED9). So far, I have successfully altered the color ...

Are there any alternatives to using <HR/> for creating lines in Bootstrap 3?

While working on my page design using Bootstrap 3, I noticed that the `` tag has too much margin. This is causing it to not fit well with the overall compact look of my page. Do you have any alternative options for drawing a line in Bootstrap 3 that woul ...

Stacked on top of one another are in-line block items

I've been working on this code for a while now, but I can't seem to get it right. My goal is to create a horizontal line of navigation links with the first link aligned to the left and the rest following in sequence like a text line. However, a ...

The intricate structure of Mongoose models and the specific order of module requirements in

I'm struggling to figure out the best way to organize my Mongoose model files to avoid dependency issues when requiring them. With multiple model files, I find myself encountering errors when one file requires another for reference and they're no ...

When attempting to manage errors in mongoose.findOne, I am encountering the issue of receiving an 'Unhandled 'error' event'

Handling 'error' Events with Mongoose Attempting to handle errors in the mongoose.findOne() function led me to try using a second parameter in this manner: mongoose.findOne({ uuid: uuid }, (err,doc)). However, I encountered an issue where no err ...

Manipulating the location where a dropdown menu intersects with a button

Is there a way to adjust the drop-down menu positioning so that it aligns with the button on the top right side of the menu pop-up, rather than the top left as it currently does? Below is the code I have borrowed from an example on W3Schools. .dropbtn ...

The navigation bar logo on my website has mysteriously vanished

Even though my main website is built with Wordpress, I decided to start a blog using Tumblr. You can visit my website here: And here is my blog: I tried to replicate the same structure of my website on my Tumblr theme. However, I encountered an issue w ...

The dropdown in the Material UI GridList appears excessively wide

Currently, I'm attempting to design a grid-shaped drop-down menu in Material UI. Most of the dropdowns available in the documentation are either a single column or a single row. I tried utilizing a menu component that includes a GridList, which almost ...

req.user and Is Authenticated are never true

Working on a project using react in conjunction with express.js (within router/user.js) router.get("/", function (req, res) { console.log("this is u" , req.user) console.log(req.isAuthenticated()); if (req.user) { res.json({ user: req.user }) ...

Reorder the nested list structure

Hello there and thank you for stopping by! I am facing a challenge with a list containing multiple nestings. I am interested in changing the order of these two lists, and I am curious if this is achievable using only CSS. List item 1 List item 2 List ...

Stop the entire page from scrolling in Next JS, while still enabling individual components to scroll

My ultimate goal is to have a fixed, sticky menu bar at the top of my app, followed by a div/component that houses the remaining content and does not scroll itself, while still allowing sub-components the ability to scroll when necessary. I plan to build t ...

Is there a way to create a marker that changes color when hovering over the text directly below it?

Hi everyone, I hope you're all doing well. Currently, if you hover over the marker, it changes color. However, I want this effect to apply when hovering over the text below as well. Is there a way to create a connection between these two div elements? ...

Developing fresh sessions for every request promptly

I am facing an issue with express-session where it intermittently creates a new session (new sessionID) for each request. Sometimes, it works fine for the first few hits and then suddenly creates a new session on the next hit. This problem only occurs on m ...

Adjust the cell text overflow based on the width of the table

I am working with a table that has multiple columns. I want the first 3 columns to have a larger width than the others, specifically taking up 15% each for a total of 45% of the table's width. Currently, I am using this code in a sandbox environment: ...

How come my post isn't being saved to the page after I refresh it?

Utilizing Javascript, NodeJS, MongoDB, Express Within my application, a user is expected to enter text in an input field and upon clicking the submit button, the text should appear on the page. I have succeeded in posting text to the page; however, after ...

Angularjs Socket.io Integration

I am working on implementing websockets in my Angular/nodejs application using socket.io. My main goal is to maintain a "live" array on the server of documents that are currently unavailable for editing (due to someone else already editing them). I starte ...

Arrangement of images in an array

Here's the scenario I'm facing. https://i.stack.imgur.com/FbAfw.jpg So, I have an array of images that I want to use to create a gallery with a specific layout. I've tried using grid and playing around with :nth-child(even) and :nth-child( ...