How can I move the following markup after the one loading jQuery and drupalsettings?
<script src="https://abc.ai/js/w?key=abc.jdnwVFfn4YUZA0in"></script>
Actually, the order is the one in the following markup.
<script type="application/json" data-drupal-selector="drupal-settings-json">{"path":{"baseUrl":"\/","scriptPath":null,"pathPrefix":"","currentPath":"node","currentPathIsAdmin":false,"isFront":true,"currentLanguage":"en"},"pluralDelimiter":"\u0003","ajaxTrustedUrl":{"\/search\/node":true},"user":{"uid":0,"permissionsHash":"a791675a6fdb4f639fabce88c7e91295566b58e25f936b9d181582d9321c503f"}}</script>
<script src="/core/assets/vendor/jquery/jquery.min.js?v=3.2.1"></script>
<script src="/core/misc/drupalSettingsLoader.js?v=8.5.1"></script>
<script src="/modules/abc/js/abc.js?v=1.x"></script>
I used hook_page_bottom()
to attach the script in the abc module.
function acobot_page_bottom(array &$attachments) {
$attachments['#attached']['library'][] = 'acobot/acobot-initialise';
$attachments['acobot'][] = [
[
'#type' => 'html_tag',
'#tag' => 'script',
'#attributes' => array('src' => 'https://acobot.ai/js/w?key=' . $token),
],
'acobot-token',
];
}
The content of the abc.libraries.yml file is the following.
abc-initialise:
version: 1.x
js:
js/abc.js: {}
dependencies:
- core/jquery
- core/drupalSettings
I added weight in the below code(instead of #attached in hook_page_bottom) but it does not change the position .
function acobot_library_info_alter(&$libraries, $extension) {
$libraries['acobot'] = array(
'version' =>'1.x',
'js' => array(
'acobot/acobot.js' => array(
'#weight' => 100,
),
'dependencies' => array(
0 => 'core/jquery',
1 => 'core/drupalSettings'
)
),
);
return $libraries;
}