{"action":"created","issue":{"url":"https://api.github.com/repos/gantry/gantry5/issues/876","labels_url":"https://api.github.com/repos/gantry/gantry5/issues/876/labels{/name}","comments_url":"https://api.github.com/repos/gantry/gantry5/issues/876/comments","events_url":"https://api.github.com/repos/gantry/gantry5/issues/876/events","html_url":"https://github.com/gantry/gantry5/issues/876","id":108491835,"number":876,"title":"The same script loads multiple times when loaded from both \"page_head.html.twig\" and a particle","user":{"login":"JoomFX","id":7753940,"avatar_url":"https://avatars.githubusercontent.com/u/7753940?v=3","gravatar_id":"","url":"https://api.github.com/users/JoomFX","html_url":"https://github.com/JoomFX","followers_url":"https://api.github.com/users/JoomFX/followers","following_url":"https://api.github.com/users/JoomFX/following{/other_user}","gists_url":"https://api.github.com/users/JoomFX/gists{/gist_id}","starred_url":"https://api.github.com/users/JoomFX/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/JoomFX/subscriptions","organizations_url":"https://api.github.com/users/JoomFX/orgs","repos_url":"https://api.github.com/users/JoomFX/repos","events_url":"https://api.github.com/users/JoomFX/events{/privacy}","received_events_url":"https://api.github.com/users/JoomFX/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/gantry/gantry5/labels/bug","name":"bug","color":"fc2929"}],"state":"open","locked":false,"assignee":null,"milestone":{"url":"https://api.github.com/repos/gantry/gantry5/milestones/17","html_url":"https://github.com/gantry/gantry5/milestones/5.1.5","labels_url":"https://api.github.com/repos/gantry/gantry5/milestones/17/labels","id":1278578,"number":17,"title":"5.1.5","description":"","creator":{"login":"mahagr","id":854915,"avatar_url":"https://avatars.githubusercontent.com/u/854915?v=3","gravatar_id":"","url":"https://api.github.com/users/mahagr","html_url":"https://github.com/mahagr","followers_url":"https://api.github.com/users/mahagr/followers","following_url":"https://api.github.com/users/mahagr/following{/other_user}","gists_url":"https://api.github.com/users/mahagr/gists{/gist_id}","starred_url":"https://api.github.com/users/mahagr/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mahagr/subscriptions","organizations_url":"https://api.github.com/users/mahagr/orgs","repos_url":"https://api.github.com/users/mahagr/repos","events_url":"https://api.github.com/users/mahagr/events{/privacy}","received_events_url":"https://api.github.com/users/mahagr/received_events","type":"User","site_admin":false},"open_issues":13,"closed_issues":23,"state":"open","created_at":"2015-08-29T07:38:24Z","updated_at":"2015-09-28T11:40:44Z","due_on":"2015-09-27T21:00:00Z","closed_at":null},"comments":11,"created_at":"2015-09-26T19:55:42Z","updated_at":"2015-09-28T11:44:11Z","closed_at":null,"body":"@w00fz @mahagr Hey guys,\r\n\r\nI don't know if this is the expected behavior or not so I want to discuss it with you.\r\n\r\nAs you know, when you use `JHtml::_('jquery.framework');` or in Gantry5 the newly added `{{ joomla.html('jquery.framework') }}` it loads the jQuery assets only once, no matter how many times you have used this code.\r\n\r\nAlso, as far as I know, if you load the same script (from exactly the same location, with exactly the same syntax) from different places it should load the asset just once.\r\n\r\nSo, here's my scenario... I load a script and a stylesheet globally from the `page_head.html.twig` file. These assets bring some additional features so I will use them in all my templates. Here's the code I use in the `page_head.html.twig` file:\r\n\r\n```\r\n<link rel=\"stylesheet\" href=\"{{ url('gantry-theme://css/mycss.min.css') }}\" type=\"text/css\"/>\r\n<script src=\"{{ url('gantry-theme://js/myscript.min.js') }}\" type=\"text/javascript\"></script>\r\n```\r\n\r\nNow, I've built some nice particles that use the features from the above assets. And I want to release these particles for free. It means that these particles must work in all G5 Templates. In order to achieve this I need to load the above assets from the particle itself. Here's the code I use in the particle:\r\n\r\n```\r\n\t{% assets in 'head' with { priority: 0 } %}\r\n\t\t<link rel=\"stylesheet\" href=\"{{ url('gantry-theme://css/mycss.min.css') }}\" type=\"text/css\"/>\r\n\t\t<script type=\"text/javascript\" src=\"{{ url('gantry-theme://js/myscript.min.js') }}\"></script>\r\n\t{% endassets -%}\r\n```\r\n\r\nAnd here comes the strange thing. The stylesheet (`mycss.min.css`) is loaded just once, as expected, but the script (`myscript.min.js`) is loaded twice.\r\n\r\nIs this the expected behavior? And can it be enhanced so if G5 detects that absolutely the same script is loaded more than once, it actually loads the asset only once?\r\n\r\nA workaround is to maintain two versions of each particle - one that will come with my templates (nothing will be loaded from the particle) and another one that will be released for free (the assets will be loaded from the particle). But this is really not nice :smile: \r\n\r\nP.S. It is really strange that the stylesheet is loaded just once and the script is loaded twice."},"comment":{"url":"https://api.github.com/repos/gantry/gantry5/issues/comments/143720100","html_url":"https://github.com/gantry/gantry5/issues/876#issuecomment-143720100","issue_url":"https://api.github.com/repos/gantry/gantry5/issues/876","id":143720100,"user":{"login":"mahagr","id":854915,"avatar_url":"https://avatars.githubusercontent.com/u/854915?v=3","gravatar_id":"","url":"https://api.github.com/users/mahagr","html_url":"https://github.com/mahagr","followers_url":"https://api.github.com/users/mahagr/followers","following_url":"https://api.github.com/users/mahagr/following{/other_user}","gists_url":"https://api.github.com/users/mahagr/gists{/gist_id}","starred_url":"https://api.github.com/users/mahagr/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mahagr/subscriptions","organizations_url":"https://api.github.com/users/mahagr/orgs","repos_url":"https://api.github.com/users/mahagr/repos","events_url":"https://api.github.com/users/mahagr/events{/privacy}","received_events_url":"https://api.github.com/users/mahagr/received_events","type":"User","site_admin":false},"created_at":"2015-09-28T11:44:11Z","updated_at":"2015-09-28T11:44:11Z","body":"If you want the template to work with older versions of Gantry (looking into this now), the answer is you need to override the file in `/twig` directory. Otherwise you may want to wait me to close this issue."}}