在drupal8中导入js文件

webpenson, 1 六月, 2021

想要导入js  一些在head 一些在最后

官方文档https://www.drupal.org/docs/theming-drupal/adding-stylesheets-css-and-javascript-js-to-a-drupal-theme

Additional Javascript Configuration

Asset loading order

As you would expect, the order in which the files are listed is the order in which they will load. By default, all JS assets are now loaded in the footer. JS for critical UI elements that cannot be shown unless their corresponding JS has run can be loaded in the header if needed like so:

js-header:
  header: true
  js:
    header.js: {}

js-footer:
  js:
    footer.js: {}

Set the header property to true, to indicate that the JavaScript assets in that asset library are in the 'critical path' and should be loaded from the header. Any direct or indirect dependencies of libraries declared in this way will also automatically load from the header, you do not need to declare them individually for them to be available. This is the meaning of the phrase 'critical path', once an asset is declared to be in the header it is 'critical' for that asset and all of its dependencies to load first.

但是我加上去没效果

info文件

libraries:

- yiqiuxj/global-styling

- yiqiuxj/global-scripts

libiraries文件

global-styling:

version: 1.x

css:

theme:

css/aos.css: {}

css/jquery.mb.YTPlayer.min.css: {}

css/style.css: {}

js:

js/jquery-3.4.1.min.js: {}

js/aos.js: {}

js/jquery.mb.YTPlayer.min.js: {}

js/app.js: {}

js/main.js: {}

global-scripts:

version: 1.x

header: true

js:

js/modernizr-custom.js: {}

这样是有效果的

评论