I've been working on a website, using html,css,js and xml files on my computer (not online yet). I had an images folder, but otherwise was keeping all the files in the same folder. As the work progressed, things started to get somewhat messy, so I created css, js, and xml folders and carefully updated all my html, css, and js code. I immediately ran into the "Access to restricted URI denied code: 1012" error, discussed here, here, and here. Following the recommendation in the last link, I moved the site into my localhost server. This seems to have solved the 1012 error, but I still appear to be getting other errors (my js code seems to be having problems accessing html elements). Without being too specific, what are the problems and corresponding solutions relating to moving website files into subdirectories?
-
Looking into this, it seems that, although the 1012 error has gone away, my js code still cannot read the XML files. I've tried both a path from the js directory (../xml/myXMLfile.xml) and the html (./xml/myXMLfile.xml). – iPadDeveloper2011 Aug 16 '11 at 02:09
-
2Can you put your code into jsFiddle and post the link back so we can see it. It is most likely just a path issue, but hard to diagnose without seeing the code. http://jsfiddle.net/ – Aug 16 '11 at 04:15
-
Was hoping for a "generic" answer, rather than specific to my code. At first I thought the problem might be that relative path should be relative to the html file the js is "linked" to. Then I thought a directory permissions problem. Didn't know about jsfiddle--looks like a good resource. Sick and overworked right now though, so will investigate later... – iPadDeveloper2011 Aug 17 '11 at 04:00
3 Answers
Problems associated with moving files into sub-folders.
- Images included with CSS are relative to the location of the CSS file.
- JavaScript references to other files are relative to the location of the page.
I've put together something to demonstrate
-
"JavaScript references to other files are relative to the location of the page." Makes sense. You wouldn't want js code at https://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js to have references relative to that location! I'll have to recheck if this was the problem. – iPadDeveloper2011 Aug 17 '11 at 23:39
From my own personal experience, multiple folders always creates problems.
You can make modules out of your code and put all the public resources for each module inside the same folder group, but it's worth it only on really big projects (and we're talking Yahoo, Amazon, type scale here).
If it's so complicated, multiple folders are going to make things even more difficult. Keep your folder structure simple, and reduce the complexity of your code.

- 20,846
- 10
- 65
- 96
-
I'm not far off agreeing. I do think though, that just like it is often nice to have an "images" folder, "css", "js" and "xml" folders make a lot of sense. I guess, if I can get my code sorted, I'll accept Patric's answer, if not, yours. – iPadDeveloper2011 Aug 17 '11 at 23:42
-
Sorry didn't write that very well - you should have one and only one folder for each type of resource. Check out HTML5 Boilerplate - a very good foundation for any web project. – Dan Blows Aug 18 '11 at 05:39
When moving style sheets to a css
folder, just add ./css/
to the front of your href
s in all your css link
s. Also add ../
the the front of all the image URLs in your css files.
Moving javascripts to a js
folder is similar, just add ./js/
to the front of your href
s in all your js link
s.
Moving .xml
s to an xml
folder can be more involved. Due to the 1012 error, you need to move you site to a server, if it isn't already on one. Then you need to go through your js code and add ./xml/
to the beginning of your xml references. If you've been good, you'll have a function called something like function openXMLfile(xmlFileName)
and so you'll only need to change a single line: xmlhttp.open("GET", xmlFileName+".xml", false);
to xmlhttp.open("GET", "./xml/"+xmlFileName+".xml", false);
Thanks for other answers and comments. Helped. Upvoted.

- 4,560
- 1
- 25
- 36