In the process of writing code, it is impossible to detect all errors and correct them. Writing a code, especially in large volumes, is a monotonous thing, somewhat tedious and often repeated, so the eye becomes blurry. Search and correction of errors is for me personally a separate finishing procedure. In addition to obvious errors, illogical sections of code often pop up, which also have to be rewritten, simplified, and eliminated.
In addition to fixing errors and other shortcomings, you need to take care of optimizing content for search engines. Search engines impose certain requirements on websites, which only multiply every year, and if you have not decided to deliberately close the site from indexing, you should adhere to these requirements.
Let’s start with the mistakes. There is absolutely no need to sit and look for mistakes yourself. For this, the W3C consortium provided special services. HTML code can be checked using the W3C html validator, and cascading style sheets using the W3C css validator.
I have two errors on the main page (it was at the time of writing) – both because of the google + button tag, which is not in the specification.
<g: plusone href = “http://nevor.ru”>
validator code verification
We remove these inconsistencies and the validator has no claims to my code:
validator code verification (no errors)
But google + thing is much more necessary than the picture from W3C, so I will leave these errors where they were. This is not particularly significant, especially if the main site code is validated.
The W3C validator only works with pages hosted on the Internet. If you want to check the local site for errors, I recommend using the HTML Validator plugin for Firefox. The plugin is built into the browser tab of the browser source code (called by the Ctrl + U key combination) of the browser and is based on the same algorithm as the W3C service. It looks like this:
code validator plugin for firefox
The plugin not only shows errors, but also gives tips on how it should be. I think Firefox users will appreciate this great development tool.
Cross-browser and standardized code
There is another impressive area called cross-browser compatibility. I have already touched on the topic of cross-browser compatibility in this article. Although this cannot be called mistakes, differences in the appearance of the site in different browsers make it not uncommon to edit a working (such a pun) code to please the whims of browsers. The most moody was and will remain Internet Explorer. There are various hacks for Internet Explorer that allow you to nullify these vagaries. However, many of these methods are perceived by the validator as errors (in fact, they are).
Therefore, I do not recommend using hacks. Instead, you can skillfully use conditional comments, which I also mentioned in an article on cross-browser compatibility. The example below demonstrates how to use a conditional comment to place a link to a stylesheet exclusively for IE on a page. Because it follows the main table; its styles will, according to the cascade rule, overlap previous (conflicting) ones, giving Internet Explorer different directions.
<link rel = “stylesheet” href = “style.css” type = “text / css”>
<! – [if IE]>
<link rel = “stylesheet” … type = “text / css”>
<! [endif] ->
The problem of Internet Explorer is also that from version to version errors in processing the contents of html pages for this browser are different. Therefore, some programmers check their work separately in each version of Explorer. The task in some cases is really necessary. And for its implementation, you can (and should) use the IETester program, specially created for this.
I also advise you to download portable browsers from Portableapps.com, unpack them into separate folders, and then install and configure the Open width plug-in (Firefox) to quickly and easily check sites for cross-browser compatibility. Various players, galleries and other bells and whistles are also very desirable to view in all browsers before implementing. Fortunately, almost always for this they place demos. This is about errors.
Now a little about code optimization. It consists in every possible simplification of designs and solutions, in order to reduce the code as much as possible without loss of quality and functionality (to optimize). Repeating sections (as an option) can be combined and represented as a php variable.
<? php $ img = “<img src = ‘logo.jpg’ alt = ‘logo’>”;?>
<? php echo “$ img”;?>
Very often programmers duplicate sections of code or commands are called ten times
echo “<div class = ‘main’> ……”;
echo “<span class = ‘adress’> …….”;
echo “<button id = ‘send’ type = ‘button’> …..”;
echo “</button> </span> </div>”;
when you can and need one:
$ result = “<div class = ‘main’> ……”;
$ result. = “<span class = ‘adress’> …….”;
$ result. = “<button id = ‘send’ type = ‘button’> …..”;
$ result. = “</button> </span> </div>”;
echo $ result;