Hi, I’m sorry if this is a terrible newbie question... I’ve read the topics about using css files as modx documents and it’s working. So I tried to do the same thing with a javascript file: I created a new document, settings: text/javascript, no template. I put my script inside and linked to it from the template the same way as my css files. However, it’s not working

The path (eg.
http://mysite.com/script.js) is ok: if I look it up directly in my browser, I can see the file. And the javascript itself is ok too, because when I put it inside my assets folder and link there from my html file, it’s working. Any ideas?
Thanks for MODx - I love it!
Hi,
did you set the template for the js doc in modx to blank ?
:-)
EDIT: I’ve read too fast, it seems that you’ve already set it to blank.
I did! It’s weird, no?
Thanks for MODx - I love it!
Can you post the bit of the tempate that has the call to your js document?
Sure. This is working:
<script type="text/javascript" src="assets/templates/astronaute/scripts/ufo.js"></script>
This is not working:
<script type="text/javascript" src="ufo.js"></script>
http://mysite.com/ufo.js exists (I can go there with my browser) and its contents are exactly the same as
http://mysite.com/assets/templates/astronaute/scripts/ufo.js
I’m probably making some very obvious mistake here, if that’s the case I apologize
Thanks for MODx - I love it!
-
MODX Staff
- 12,272 Posts
if mysite.com/ufo.js is working but you do not have a ufo.js file in your site root, then you have a document with the alias of "ufo.js". If the second doesn’t work, it means you don’t have the file uploaded into that location. Probably a simple typo somewhere, and impossible to determine anything more without access to your server or more details (like real URLs). If you have friendly alias paths on, you’re probably missing a base href in your document head section, or have it below the calls to your javascript and css.
Typically, but certainly not a requirement or hard rule, you’ll see javascript files in assets/js/.
Ryan Thrash, MODX Co-Founder
Follow me on Twitter at @rthrash or catch my occasional unofficial thoughts at thrash.me
Thanks for your help. The site is here, BTW:
http://www.arlingenarling.com/nieuw/
I have set a base url and in the manager there’s a document with the alias of ufo.js. The site is in a
subdirectory folder, would that make a difference?
I’ll just put my scripts in my assets folder then. It’s not really a problem, I’m just trying to understand why it isn’t working (and in the process learn more about MODx

).
Thanks for MODx - I love it!
Thanks, but no, it’s not working. This way the path becomes: www.arlingenarling.com/nieuw/nieuw/ufo.js, which isn’t right.
Thanks for MODx - I love it!
-
MODX Staff
- 10,725 Posts
Definitely the base href issue -- you need one in your HEAD section if you want to reference things relative to the site root. Otherwise, the site being in a subdirectory, it’s assuming relative to the current folder location specified in the URI of the linked resource, which would be calculated improperly without the <base href="[(site_url)]" /> tag appearing in your head before any paths.