Jump to content

Odd occurrences with JS


phppup

Recommended Posts

An HTML file was getting too large so I decided to attach some JavaScript as a src="add.js" rather than sitting the JS directly in the HTML file.

When add.js was stored in the same folder as the HTML, the connection worked. But when moved up in the h hierarchy by one level, I couldn't find a connection. I thought ../thisLevel/add.js would work (and I tried every variation) but got nothing. 

Suspiciously, after settling on leaving the JS in the same folder as the HTML, I discover that the response I was getting was outdated - as if cached.

[I changed an alert("hello") to "HELLO 2" but was alerted hello on screen)

After emptying the cache, I got variations of effectiveness from the script. 

This made it impossible to review since I didn't know if errors were caused by the script, a malfunction of cache, or otherwise.

Is this a browser, server, or computer issue?

What is the remedy?

Is it a common occurrence when JS is outside of the HTML code?

Edited by phppup
Link to comment
Share on other sites

2 hours ago, phppup said:

Is this a browser, server, or computer issue?

One or more of those, yes. Impossible to say just with your description.

2 hours ago, phppup said:

What is the remedy?

Depends.

2 hours ago, phppup said:

Is it a common occurrence when JS is outside of the HTML code?

No.

Link to comment
Share on other sites

Additional info:

At the same time that these issues occurred, I visited the webpage on my cellphone (different WiFi network, different anti-virus/firewall/security) and got the same ODDBALL occurrences.

 

UPDATE: This morning I was working from a different location on a different webpage (same website) and all was fine. Then, suddenly, changes to HTML and PHP echos were ineffective.

 

Am I correct in assuming that these clues are pointing me in the direction of the hosting server?

Is this likely an internal problem that they need to resolve, or is there a way that I can help PUSH my updated code so that it becomes active?

NOTE: although code is not being displayed to reflect changes, the files are being saved and can be recalled with the latest info retained.

Link to comment
Share on other sites

There is no reason to use parent child directories in pathing to web resources, and plenty of ways doing so can be the source of problems.

If your webroot is  /foo, then have a directory under /foo like /foo/js.  Put your .js files in the /foo/js folder.  In your example you have a .js named add.js.

At that point you can refer to add.js inside your html via the relative path: 

 

<script src="/js/add.js"></script>

Notice the leading '/' which indicates the webroot directory is the parent.

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.