Why is my theme library load on every page?











up vote
1
down vote

favorite












I'm beginning with D8, but I work a lot with D7 and Magento. I follow the developer documentation to add a library in my theme, and I don't understand why it's loading it on every page. I only want attach it to a brunch of page with a preprocess hook. Could you help me please?



In my theme.libraries.yml I add this at the end:



hover3d:
js:
js/hover3d.js: {}


In my theme.info.yml I add under libraries "theme/hover3d".



Here is specific information:




  • I deactivated JavaScript/CSS compression in the back office and in my settings.local.php file

  • My theme is a sub theme of bootstrap_barrio

  • My Drupal version is 8.6.3

  • There is no custom / contrib modules yet

  • I discover it by inspecting my page


js




  • I don't really understand how JavaScript parts are loaded, but I suppose it's with lazy builders which are called placeholder and in D8 for rendering JavaScript there are two (or more) which are js-placeholder and js-bottom-placeholder. I see in my HTML structure that in the js-placeholder is only loaded modernizer and in the js-bottom-placeholder all the others. I don't know if this is a correct JavaScript rendering procedure, so I keep it here if it can help you.










share|improve this question




























    up vote
    1
    down vote

    favorite












    I'm beginning with D8, but I work a lot with D7 and Magento. I follow the developer documentation to add a library in my theme, and I don't understand why it's loading it on every page. I only want attach it to a brunch of page with a preprocess hook. Could you help me please?



    In my theme.libraries.yml I add this at the end:



    hover3d:
    js:
    js/hover3d.js: {}


    In my theme.info.yml I add under libraries "theme/hover3d".



    Here is specific information:




    • I deactivated JavaScript/CSS compression in the back office and in my settings.local.php file

    • My theme is a sub theme of bootstrap_barrio

    • My Drupal version is 8.6.3

    • There is no custom / contrib modules yet

    • I discover it by inspecting my page


    js




    • I don't really understand how JavaScript parts are loaded, but I suppose it's with lazy builders which are called placeholder and in D8 for rendering JavaScript there are two (or more) which are js-placeholder and js-bottom-placeholder. I see in my HTML structure that in the js-placeholder is only loaded modernizer and in the js-bottom-placeholder all the others. I don't know if this is a correct JavaScript rendering procedure, so I keep it here if it can help you.










    share|improve this question


























      up vote
      1
      down vote

      favorite









      up vote
      1
      down vote

      favorite











      I'm beginning with D8, but I work a lot with D7 and Magento. I follow the developer documentation to add a library in my theme, and I don't understand why it's loading it on every page. I only want attach it to a brunch of page with a preprocess hook. Could you help me please?



      In my theme.libraries.yml I add this at the end:



      hover3d:
      js:
      js/hover3d.js: {}


      In my theme.info.yml I add under libraries "theme/hover3d".



      Here is specific information:




      • I deactivated JavaScript/CSS compression in the back office and in my settings.local.php file

      • My theme is a sub theme of bootstrap_barrio

      • My Drupal version is 8.6.3

      • There is no custom / contrib modules yet

      • I discover it by inspecting my page


      js




      • I don't really understand how JavaScript parts are loaded, but I suppose it's with lazy builders which are called placeholder and in D8 for rendering JavaScript there are two (or more) which are js-placeholder and js-bottom-placeholder. I see in my HTML structure that in the js-placeholder is only loaded modernizer and in the js-bottom-placeholder all the others. I don't know if this is a correct JavaScript rendering procedure, so I keep it here if it can help you.










      share|improve this question















      I'm beginning with D8, but I work a lot with D7 and Magento. I follow the developer documentation to add a library in my theme, and I don't understand why it's loading it on every page. I only want attach it to a brunch of page with a preprocess hook. Could you help me please?



      In my theme.libraries.yml I add this at the end:



      hover3d:
      js:
      js/hover3d.js: {}


      In my theme.info.yml I add under libraries "theme/hover3d".



      Here is specific information:




      • I deactivated JavaScript/CSS compression in the back office and in my settings.local.php file

      • My theme is a sub theme of bootstrap_barrio

      • My Drupal version is 8.6.3

      • There is no custom / contrib modules yet

      • I discover it by inspecting my page


      js




      • I don't really understand how JavaScript parts are loaded, but I suppose it's with lazy builders which are called placeholder and in D8 for rendering JavaScript there are two (or more) which are js-placeholder and js-bottom-placeholder. I see in my HTML structure that in the js-placeholder is only loaded modernizer and in the js-bottom-placeholder all the others. I don't know if this is a correct JavaScript rendering procedure, so I keep it here if it can help you.







      8 theming libraries






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 23 at 0:43









      Peter Mortensen

      1513




      1513










      asked Nov 22 at 16:40









      Kpone

      148110




      148110






















          1 Answer
          1






          active

          oldest

          votes

















          up vote
          4
          down vote



          accepted











          In my theme.info.yml i add under libraries "theme/hover3d".




          That's why it's loaded on every page. libraries in the theme info file is:




          A list of libraries (which can contain both CSS and JavaScript assets) to add to all pages where the theme is active.




          To add it contextually, attach it to a relevant render array. For example:



          function MYTHEME_preprocess_node(&$variables) {
          // Library will only be loaded when a node is rendered on the page.
          $variables['#attached']['library'] = 'theme/hover3d';
          }


          See Adding stylesheets (CSS) and JavaScript (JS) to a Drupal 8 theme for more information.






          share|improve this answer





















          • Oh that's why ! I thinked that only global-styling and global-js was globally loaded i misunderstands the docs. Thanks
            – Kpone
            Nov 22 at 16:48












          • Yeah global-* is quite confusing
            – Clive
            Nov 22 at 17:04











          Your Answer








          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "220"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          convertImagesToLinks: false,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fdrupal.stackexchange.com%2fquestions%2f272904%2fwhy-is-my-theme-library-load-on-every-page%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          up vote
          4
          down vote



          accepted











          In my theme.info.yml i add under libraries "theme/hover3d".




          That's why it's loaded on every page. libraries in the theme info file is:




          A list of libraries (which can contain both CSS and JavaScript assets) to add to all pages where the theme is active.




          To add it contextually, attach it to a relevant render array. For example:



          function MYTHEME_preprocess_node(&$variables) {
          // Library will only be loaded when a node is rendered on the page.
          $variables['#attached']['library'] = 'theme/hover3d';
          }


          See Adding stylesheets (CSS) and JavaScript (JS) to a Drupal 8 theme for more information.






          share|improve this answer





















          • Oh that's why ! I thinked that only global-styling and global-js was globally loaded i misunderstands the docs. Thanks
            – Kpone
            Nov 22 at 16:48












          • Yeah global-* is quite confusing
            – Clive
            Nov 22 at 17:04















          up vote
          4
          down vote



          accepted











          In my theme.info.yml i add under libraries "theme/hover3d".




          That's why it's loaded on every page. libraries in the theme info file is:




          A list of libraries (which can contain both CSS and JavaScript assets) to add to all pages where the theme is active.




          To add it contextually, attach it to a relevant render array. For example:



          function MYTHEME_preprocess_node(&$variables) {
          // Library will only be loaded when a node is rendered on the page.
          $variables['#attached']['library'] = 'theme/hover3d';
          }


          See Adding stylesheets (CSS) and JavaScript (JS) to a Drupal 8 theme for more information.






          share|improve this answer





















          • Oh that's why ! I thinked that only global-styling and global-js was globally loaded i misunderstands the docs. Thanks
            – Kpone
            Nov 22 at 16:48












          • Yeah global-* is quite confusing
            – Clive
            Nov 22 at 17:04













          up vote
          4
          down vote



          accepted







          up vote
          4
          down vote



          accepted







          In my theme.info.yml i add under libraries "theme/hover3d".




          That's why it's loaded on every page. libraries in the theme info file is:




          A list of libraries (which can contain both CSS and JavaScript assets) to add to all pages where the theme is active.




          To add it contextually, attach it to a relevant render array. For example:



          function MYTHEME_preprocess_node(&$variables) {
          // Library will only be loaded when a node is rendered on the page.
          $variables['#attached']['library'] = 'theme/hover3d';
          }


          See Adding stylesheets (CSS) and JavaScript (JS) to a Drupal 8 theme for more information.






          share|improve this answer













          In my theme.info.yml i add under libraries "theme/hover3d".




          That's why it's loaded on every page. libraries in the theme info file is:




          A list of libraries (which can contain both CSS and JavaScript assets) to add to all pages where the theme is active.




          To add it contextually, attach it to a relevant render array. For example:



          function MYTHEME_preprocess_node(&$variables) {
          // Library will only be loaded when a node is rendered on the page.
          $variables['#attached']['library'] = 'theme/hover3d';
          }


          See Adding stylesheets (CSS) and JavaScript (JS) to a Drupal 8 theme for more information.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 22 at 16:46









          Clive

          146k13246287




          146k13246287












          • Oh that's why ! I thinked that only global-styling and global-js was globally loaded i misunderstands the docs. Thanks
            – Kpone
            Nov 22 at 16:48












          • Yeah global-* is quite confusing
            – Clive
            Nov 22 at 17:04


















          • Oh that's why ! I thinked that only global-styling and global-js was globally loaded i misunderstands the docs. Thanks
            – Kpone
            Nov 22 at 16:48












          • Yeah global-* is quite confusing
            – Clive
            Nov 22 at 17:04
















          Oh that's why ! I thinked that only global-styling and global-js was globally loaded i misunderstands the docs. Thanks
          – Kpone
          Nov 22 at 16:48






          Oh that's why ! I thinked that only global-styling and global-js was globally loaded i misunderstands the docs. Thanks
          – Kpone
          Nov 22 at 16:48














          Yeah global-* is quite confusing
          – Clive
          Nov 22 at 17:04




          Yeah global-* is quite confusing
          – Clive
          Nov 22 at 17:04


















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Drupal Answers!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.





          Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


          Please pay close attention to the following guidance:


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fdrupal.stackexchange.com%2fquestions%2f272904%2fwhy-is-my-theme-library-load-on-every-page%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Bundesstraße 106

          Verónica Boquete

          Ida-Boy-Ed-Garten