How to include jQuery Once on your Drupal 8 pages
(as well as the Drupal object, Drupal.settings, and Drupal AJAX)
Much in the same way that jQuery is not included by default on Drupal 8 sites, neither is the very useful jQuery.once() plugin.
To be able to use jQuery Once, just create a library in your theme or module’s libraries file. The library should reference your JS file that uses jQuery Once, and it should list both jQuery and jQuery Once as dependencies coming from core:
Be wary of including the library on every single page that is styled by your theme as this would have performance implications, particularly if you got into the habit of adding all additional plugins to your global styling library.
To find out more about how to then attach the library to your theme or module’s output only when it is required, have a read of these two very useful links on Drupal.org: