Forum Moderators: open

Message Too Old, No Replies

Block comments causing an error when included on the page?

         

csdude55

2:26 am on May 30, 2018 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I have a separate JS file, and while in production I have a lot of comments throughout. I tend to write block comments like this:

/**** TITLE
* this is a description
*
* Reference:
* https://www.example.com
*/


The * before each line isn't really necessary, it's just a habit I got in to a million years ago.

I recently used PHP's include() to include the JS file to the page for a speed test, and what I discovered was that a lot of the block comments were actually being printed to the output of the page instead of being recognized as a comment. They worked fine when I used <script src='example.js'></script>, they just don't work as part of the HTML page.

What's the deal, are block comments not acceptable on an HTML page?

lucy24

2:46 am on May 30, 2018 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



They worked fine when I used <script src='example.js'></script>, they just don't work as part of the HTML page.
When they're included in the page, what exactly is the container they're being included into? (Wouldn't it be fun if it turned out you simply forgot the <script> tags? Too much to hope, I guess, but I used to make the analogous mistake with css all the time until I got it internalized.)

csdude55

2:54 am on May 30, 2018 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I wish! But I don't think it's that easy :-( Here's the exact code:

echo "<style>\n";
include $wwwpath . '/includes/styles.css';
echo "\n</style>\n\n";

echo "<script>\n";
include $wwwpath . '/includes/javascript.js';
echo "\n</script>\n\n";

$nocookie = 1;

echo <<<EOF
</head>

blah blah blah

EOF;


And as far as I can tell, removing this block fixes the problem:

/*** Infinite Scroll
*http://scrollmagic.io/examples/advanced/infinite_scrolling.html
*
* Usage:
*
* 1. Wrap content to be loaded in 2 DIV tags with unique IDs. The first ID is "listID" and the second is "itemID"
* 2. Create a button with the link to the next page, and give it a class of "nextClass". It needs to be nested in those first DIVs
* 3. Add these after the second closing DIV (second one is optional):
*<div id="classifiedLoader">$('#classifiedLoader').html(loading);</script></div>
*<div id="classifiedStart"></div>
* 4. Include this:
*var scroll = {
*controller: '',
*scene: '',
*
*listID: '#classifiedList',
*itemID: '#itemList',
*nextClass: '.nextClassified',
*loadingID: '#classifiedLoader',
*
*// Optional, if you want the fragment to load earlier in the page
*startLoad: '#classifiedStart',
*padding: 400,
*
*// Optional, adjust how long it takes to load next page
*speed: 3000,
*
*// Optional, if you want to run a function with each iteration
*callback: 'showBanner',
*startCount: $data_b,
*increment: 2,
*
*// Optional, to make sure aside doesn't exceed section
*section: 'section',
*aside: 'aside',
*
*// Update pushState; 1 for true, blank for false
*push: 1
*};
*
*infiniteScroll(scroll);
*/


I changed the * to // so it was a series of 1-line comments instead of one large block comment, but had the same error. So I don't think the * is the issue...

lucy24

4:57 am on May 30, 2018 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



See if you can pinpoint exactly where the comments stop being invisible and fall into the visible HTML. I've got something niggling at the back of my memory involving unintended ending of comments, but it will take some further brain-racking to dredge up exactly what the offending character or string was. Is it possible something needs to be escaped?

Gosh, it's fun watching this site's auto-formatting struggle with code snippets. It seems to speak a language in which ' single apostrophes introduce a comment. (Doesn't BASIC do that?) Or is it just unhappy at what it perceives as an odd number of quotation marks?

keyplyr

6:14 am on May 30, 2018 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Not sure I understand why you use comments. What's the point when you're writing for yourself? Who's the comment for?

csdude55

6:28 am on May 30, 2018 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I think I figured it out... I still understand the "why", though.

After removing one line at a time, I narrowed it down to the #3 header. There's this:

<div id="classifiedLoader">$('#classifiedLoader').html(loading);</script></div>


The </script> was the problem, the HTML page thought that the script was supposed to end there. So everything after that came through as raw HTML.


Gosh, it's fun watching this site's auto-formatting struggle with code snippets. It seems to speak a language in which ' single apostrophes introduce a comment. (Doesn't BASIC do that?)

I've gotten tickled at that in the past myself :-) Sometimes I'll post code, and for whatever reason the whole thing is in light gray and hard to read!

In this case, though, it sent me on a wild goose chase... I saw the *// Optional in my post and thought that was the problem, that it was seeing the *// as the end of the comments! But in my actual code, I have several spaces between the * and //; just the formatting didn't transfer over.

I do wish it just changed code to pre, changed < and > to &lt; and &gt; respectively, and didn't bother with the auto-formatting. I doubt anyone here would lack the ability to figure out the rest...

Was it BASIC that did that with the apostrophe? I don't quite remember, I haven't used BASIC since high school! And that was a loooooong time ago :'-( Or maybe it was PASCAL?