Topic on Project:Support desk

Custom skin JavaScript only loads once after being modified

5
AbyxDev (talkcontribs)

I am designing a new skin for a wiki I use, and this skin requires some custom JavaScript. I specified everything as instructed in Manual:Skinning Part 2, but the JavaScript only loads the first time I load the page after modifying the JS file.

As a step sequence, I:

  1. Changed the JavaScript file for the skin (for reference, it is in SkinName/resources/skin.js)
  2. Loaded up a page on the wiki, the JavaScript works as expected
  3. Reloaded the page (or loaded another page), the JavaScript is not present and the browser does not even fetch the file; clearing cache has no effect

Anyone have any idea how I can fix this issue? Many thanks.

Osnard (talkcontribs)

The browser does not load the file directly. It is delivered (and minified) by the load.php entrypoint. The issue you are describing is probably related to the resourceloader caching mechanism. Have a look at "ResourceLoader/Developing with ResourceLoader".

AbyxDev (talkcontribs)

After reading through that page, I found that setting $wgResourceLoaderDebug = true; made the JS load every time! Thank you for directing me to that link.

TheDJ (talkcontribs)

That should not be necessary however and should come with a hefty performance penalty.. It means that your script is doing something wrong. Often causes are usage of global variables, or it not being async loading compatible.

Ciencia Al Poder (talkcontribs)

As TheDJ pointed out, this may be a timing problem, where it loads the first time because it's not cached by the browser, and once cached it's executed before other prerequisites causing an exception or access a DOM element still not present on the page.

Making debug the default may solve the issue but it causes performance problems and may not always work if it depends on the load order of the scripts.

Reply to "Custom skin JavaScript only loads once after being modified"