Referencing a Javascript file without using queue_js_file

I am using Omeka Classis and I need to include an external JS file (@babel/polyfill) to get Internet Explorer to display my site correctly (due to some other JS libraries I am using).

The js file I’m trying to include is big and causing a hit so I only want it to load for IE users. I can’t do this with queue_js_file as this PHP execution will happen server side.

So to do this I have the following javascript in the page where I need the script (itemw/browse):
(I’ve omitted the logic for testing for IE)

document.write('<script type="text/javascript" src="../javascripts/test.js"><\/script>');

When I inspect the resultant page I can see that the javascript call has been created bu when I click on the link to the js file I get:

exception ‘Zend_Controller_Dispatcher_Exception’ with message ‘Invalid controller specified (javascripts)’

I think this is to do with the framework and MVC preventing me because I’m trying to work outside the way it works.

Is there a way I can access the underlying file structure to reference this file directly from the client side?


This isn’t an answer to your question, but do you get the same error if you use an absolute path? It may well be that the application is rewriting your path, but I’ve often run into problems like this because I mistook how a relative path would be interpreted.

If it works with an absolute path the solution should be pretty easy. If not, it will be more work, and it’s been some time since I’ve diagnosed anything along those lines. I do know that .htaccess files are sometimes a culprit in these issues.

I meant to reply to this earlier, sorry.

You can use web_path_to to get the server-relative path to a given file: this is what the queue_ functions themselves use.

But basically bkalish is on the right idea, your path is just wrong. There’s no way really to write a relative URL like that in Omeka since generally the same code can appear on multiple pages possibly at different “levels” of the hierarchy, so you won’t have the right number of ..'s in your path. You generally want to use a server-relative path (that is, a path starting with a /) so that it will work the same no matter what page it appears on. Omeka’s built-in linking and loading functions generally use server-relative URLs.