How to dynamically load static resources according to different pages when nodejs renders templates?

  node.js, question

All pages have a common beginning and end.header.ejs footer.ejs
Each page will be loaded with common head and tail, and different css and js will be loaded according to different pages. What should I doElegantDo you have the effect of having common head and tail and loading different static files?
Can we put all these loaded static resources in one placeThe same profile inside(I’ve seen people do this, but I forgot how to do it), for example, it’s called entry, instead of specifying what is loaded separately for each page.

Thank you for inviting me. I personally don’t like it very muchejsOf (too ugly), I can only talk about the basic idea of doing this:

First of all, because of “different pages”, it is bound to be inres.render(view [, locals] [, callback])ThelocalsThe object inside has a special field to represent the page type. Is this understandable? For example:{ pageType: 'home' }. Otherwise all renderings are publicheaderfooter, how to distinguish?

Secondly, it is inheader.ejsOr ..footer.ejsInside configures static resources according to fields of newly added page types, such as:

< percentage if (locales.pagetype = = =' home') {percentage >
 <link rel="stylesheet" href="xxx/home.css" />
 < percentage} else if (locales.pagetype = = =' about') {percentage >
 <link rel="stylesheet" href="mmmx/about.css" />
 < percentage} percentage >

Of courseejsYou may feel too tired to write like this, is it possible to do so atjsWrite a map? Of course, for example:

var mapping = {
 home: 'xxx/home.css',
 about: 'mmmx/about.css'
 };

When rendering directly tolocalsObject inside Injects OneresourceField, similar to:

res.render(view, {
 resource: mapping[pageType]
 });

suchejsCan be rewritten as follows:

< link rel="stylesheet" href= "< percentage = locals.resource percentage >"/>