![]() |
#1 |
Addict
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 324
Karma: 3200000
Join Date: Oct 2015
Location: Madison, WI
Device: Kindle 5th Gen
|
Order of linked Javascripts
As a part of my workflow, I import and link two Javascript files early in a given project. I need em in a certain order, but I haven't yet been able to figure out how to get them to come in that way. It doesn't seem to insert them into the <head> alphabetically, and the order I click em in the import dialogue doesn't seem to affect it either.
It's just two files, so I usually just reorder them manually before splitting files per-chapter. But I was curious if there might be something I can do to get them to come in in the desired order in the first place. Is there? Last edited by phillipgessert; 10-15-2025 at 02:09 PM. |
![]() |
![]() |
![]() |
#2 |
Sigil Developer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 9,066
Karma: 6361556
Join Date: Nov 2009
Device: many
|
I think those links are placed immediately before the head end tag. So inserting them in order should work.
I will take a look at the code and get back to you. |
![]() |
![]() |
![]() |
#3 |
Fool
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 495
Karma: 4660650
Join Date: Feb 2003
Device: Kindle: Voyage,PW1,KOA, Kobo: Clara Colour, Nook GLP, Pocketbook verse
|
JavaScript links load asynchronously, so the second one may complete its fetch before the first one does even though the first link makes its fetch request earlier.. The fetched content (the "src" attributed) will be loaded into the open document in the order received from the relevant server(s).
|
![]() |
![]() |
![]() |
#4 |
Sigil Developer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 9,066
Karma: 6361556
Join Date: Nov 2009
Device: many
|
I think he was talking about the order the link statements are inserted into the head tag or each xhtml file. I think, without any "async" or "defer" their order in head determines their order of execution once the body has been fully loaded.
Okay, I just got to my desktop and fired it up and created an epub with 4 xhtnml files and two javascript files named "Script0001.js" and Script0002.js". I then selected the 4 html files in BookBrowser and right clicked and included them. They were inserted in that order in every xhtml file. Are you seeing something different? If I wanted the order to be reversed, I simply select the xhtml files I want to add the links too, and then right clicked and selected Link Javascripts... and when the javascript selection window opened I used the up down caret keys on the right side of dialog to swap the order of the javascript files making Script0002.js come first (and made sure they were all checked). See the attached image. Sigil then used that order of linking. So I can not recreate what you are seeing about linkage order? Last edited by KevinH; 10-15-2025 at 03:46 PM. |
![]() |
![]() |
![]() |
#5 | |
Addict
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 324
Karma: 3200000
Join Date: Oct 2015
Location: Madison, WI
Device: Kindle 5th Gen
|
Quote:
Sorry for raising the issue when I don't have an example in hand, it's something I've worked with off an on for a few months and, Murphy's Law, naturally right now it's working precisely like it's supposed to. |
|
![]() |
![]() |
![]() |
#6 |
Sigil Developer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 9,066
Karma: 6361556
Join Date: Nov 2009
Device: many
|
Figures! If you can ever figure out how to reproduce it, please do let me know. There could be a dictionary or map that does not keep order someplace in the execution but I could not see one.
This code was copied almost 100% from the link css files code as stylesheet order is important as the last sheet wins in case both are present. So it should be order consistent and preserving for the order generated by the dialog that selects the javascripts. |
![]() |
![]() |
![]() |
#7 | |
Addict
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 324
Karma: 3200000
Join Date: Oct 2015
Location: Madison, WI
Device: Kindle 5th Gen
|
Quote:
Here's what I did, in case it helps. First I did my usual routine: 1. Created a new, empty EPUB3 2. Used the DOCXImport plugin to pull in a Word file 3. Ran Mend & Prettify 4. Restructured EPUB to Sigil Norm 5. Added the JS files via Add Existing Files (two files, script.js and a jquery.js) 6. Linked Javascripts—(dialogue had script.js first, and result did too) After that, I tried to see how many of those steps I could skip and land at the same result. So, I: 1. Created a new, empty EPUB3 2. Ran Mend & Prettify 3. Added the JS files via Add Existing Files 4. Linked Javascripts This had the same result, inverted order in the dialog and in the result. So I tried this: 1. Created a new, empty EPUB3 2. Added the JS files via Add Existing Files 3. Linked Javascripts—(dialogue had jquery.js first, and result did too) That got my hopes up, thinking maybe running Mend & Prettify first caused the problem. Unfortunately though, I then tried doing it a few more times, and it started inverting the order even without Mend & Prettify. I have a user-template3.xhtml file l set up some time ago which has those links already in the <head>. I wondered if having that preconfigured was contributing to the problem, so I renamed it and tried again. Same deal as that last run though—initially, created a new file, pulled the JS files in, linked em, and the alpha order was preserved in both the dialogue and the result. Then that started inverting too. Spitballing, maybe it has to do with how many EPUBs I've got open at the same time? |
|
![]() |
![]() |
![]() |
#8 |
Sigil Developer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 9,066
Karma: 6361556
Join Date: Nov 2009
Device: many
|
So you are saying it will appear with enough repeated trials? Running mend, importing, etc, really should have nothing to do with it. If one of the scripts pre-existed in some of the files, that might cause an issue.
I will try repeating my experiment 10 times in a row to see if I can ever see the wrong order. I will let you know what I see. Last edited by KevinH; Yesterday at 11:33 AM. |
![]() |
![]() |
![]() |
#9 | |
Addict
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 324
Karma: 3200000
Join Date: Oct 2015
Location: Madison, WI
Device: Kindle 5th Gen
|
Quote:
|
|
![]() |
![]() |
![]() |
#10 |
Sigil Developer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 9,066
Karma: 6361556
Join Date: Nov 2009
Device: many
|
Okay I built en epub with 30 emtpy xhtml files. Then added 3 empty js files Script0001 to Script0003 then saved it.
Next I selected groups of 3 sequential xhtml files and inserted the order as Script 1,2,3. I repeated that 10 times and examined all 30 files and all were correct. I reloaded that test republic's and did the same things with groups of 3 files using order 2,1,3. Again after repeating thi 10 times I checked all of them and in everycase the order was 2,1,3 (correct). Then i reloaded that test epub again and did the same things with groups of 3 files at a time using order of Scripts 3,2,1. I repeated that commend 10 times until all 30 files had be edited. Checked them all in every case the order was 3, 2, 1. So 10 sets of 3 xhtml files was not enough to see any issue. I will repeat this experiment with 100 xhtml files in groups of two and see if I can recreate any out of order xhtml files afterwards. |
![]() |
![]() |
![]() |
#11 |
Addict
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 324
Karma: 3200000
Join Date: Oct 2015
Location: Madison, WI
Device: Kindle 5th Gen
|
You helped me a lot here, but maybe not quite the way you expected. I somehow didn't realize that I could intentionally reorder the scripts in that dialogue. It's obvious now, I see the little arrows at the right. Just never made the connection before.
Grateful for your time, I think my issue is resolved—I'll come back to this again if it surfaces again for whatever reason, but I doubt it will. Thanks again for all your work on this useful tool. |
![]() |
![]() |
![]() |
#12 |
Sigil Developer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 9,066
Karma: 6361556
Join Date: Nov 2009
Device: many
|
No worries. But that list of all the javascript files is generated by a concurrent multi-thread process. So the order they are presented may vary. But you control the order with the up and down keys. So you must look carefully at the order presented to you as it is not always the same as the last time you used it.
This is expected behaviour. You determine the actual order of insertion by creating the order the way you want in that Link Javascripts dialog. |
![]() |
![]() |
![]() |
#13 |
Addict
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 324
Karma: 3200000
Join Date: Oct 2015
Location: Madison, WI
Device: Kindle 5th Gen
|
Perfect explanation, luckily I only have two files, and I'm sure I can spot it right away if I need to arrow one up or down. I understand the software better now, so thank you again!
|
![]() |
![]() |
![]() |
Thread Tools | Search this Thread |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
Order multi-series storyline in reading order | plaid | Kobo Reader | 2 | 02-23-2023 04:30 PM |
Default to allow javascripts to open windows | KevinH | Sigil | 5 | 08-01-2021 07:14 AM |
Linked Resource Does Not Exist | dbird | Editor | 18 | 10-10-2017 02:22 PM |
Collections created in cloud don't order themselves by alphabetical order | septentrion | Amazon Kindle | 4 | 12-25-2016 12:21 AM |
PRS-950 Order a 950 delivered now (not pre-order) for $239.99 | sun surfer | Sony Reader | 2 | 12-16-2010 11:06 AM |