Developer forum

Forum » Templates » Er det ikke en bug? IF tags

Er det ikke en bug? IF tags

Sten Hougaard
Reply

Hej,

Der er noget som har plaget mig noget på det seneste. En SEO ekspert bemærkede store mængder af linieskift i HTML sourcen, og han påstod at det påvirkede SEO negativt. Årsag viste sig at være en Dynamicweb IF sætning. Problemet opstår hvis man (med pseudokode) skriver:

IF (my condition)
  CODE WHICH SHOULD
  NOT BE VISIBLE
  AS CONDITION IS NOT MEET
EndIF

I tilfældet ovenfor vil der kommer 3 blanke linier, selv når konditionen ikke er tilstede. Hvis det f.eks. er i et produkt loop kan det give rigtig mange blanke linier. Der burde komme intet ud når en blok af kode ikke skal vises.


Med venlig hilsen/Best regards,

Sten Hougaard
Webudvikler
E: sho@1stweb.dk

 


Replies

 
Lars Larsen
Reply

+1

 
Mikkel Ricky
Reply

Please use English in the forum. I'd like to see the source for the SEO guy's claim about whitespace affecting SEO.

Anyway, when you write a block like the one you show, you probably add a line break before the block and one after the block (for readability). These line breaks are kept because they are not inside the block. You'll probably add even more whitespace around the block (also for readability) and they will also be kept.

 

Using Razor templates generates much less whitespace than using html templates, and the reason for this is that Razor knows what is code (C#) and what is markup (html).

For example in this piece of Razor

@if («some condition») {
  <pre>«content»</pre>
}

only <pre>«content»</pre> is markup and on the markup will be rendered. In an html template you'd probably write this as

<!--@If(«some condition»)-->
  <pre>«content»</pre>
<!--@EndIf-->

and here everything between --> and <-- is markup (including all whitespace).

Best regards,
Mikkel

 

 
Morten Bengtson
Reply

Remeber to write in english, Steen :)

I think a similar "too much whitespace" issue has been reported before and nothing happened. I guess we need to use Razor templates if we want more control over the formatting of the output :/

If you want to, you can install an HTTP module to remove unnecessary whitespace and perform other optimizations, e.g. Web Markup Minifier.

 
Sten Hougaard
Reply

Thank you Morten and Mikkel.

I conclude: Dynamicweb advices you to use Razor templates as their HTML IF function is out of control.

I agree with you Mikkel: I do not see whitespaces affect SEO.

Thank you very much for replying.

/Sten

 

You must be logged in to post in the forum