Home
Home Page
The menu of a choice in forms
The loader in HTML
Konfigurirovanie a site with the help of a file .htaccess
Options-Indexes
Perenapravlenie on other address
Replacement with the image. Method Farnera
Example the first. Headings of pages
Replace cautiously
Method of overlapping by a background (Cover-up Method)
WAP (Wireless Application Protocol)
Reduction of time of loading of webs - pages with help CSS
Mnogozadachnost` in JavaMe at HTTP connection
Interaction of streams.
Nine advice for job with Web 2.0
Beginning php to the programmer or how to start to earn
Substantiation of necessity of Storehouse of the data
Misses in the data
The directory by mistakes Oracle
Forms in HTML documents
Links
 

Reduction of time of loading of webs - pages with help CSS

1. Avoid use of tables for a marking of page


Six reasons on which it is better to use CSS, instead of tables, for a marking of pages:


* Browsers analyze tables twice: first time to estimate structure of the table, and the second - for orprelenija their contents.

* Tables are displayed at once completely, instead of in process of loading.

* Tables force to use prozgrachnye a picture for definition of width of columns, etc.

* CSS demands much less a code, than the overloaded tables

* All CSS-code can be born in an external file which will be loaded all once and to be stored{kept} in a cache of a browser.

* With help CSS it is possible to supervise sequence of loading of elements of page.



2. Do not use a picture for display of the text


The majority of buttons and inscriptions can be displayed with help CSS. Look at an example:



a:link.example, a:visited.example, a:active.example {color: * fff; background: * f90; font-size:1.2em; font-weight:bold; text-decoration:none; padding:0.2em; border:4px *00f outset} a:hover.example {color: * fff; background: * fa1; font-size:1.2em; font-weight:bold; text-decoration:none; padding:0.2em; border:4px *00f inset


This CSS defines{determines} the simple button which changes the kind at prompting the cursor. Thus it is possible to create and more complex{difficult} objects.



3. Loading pictures through CSS


Some background images are better for loading through CSS. For example, to show a picture in the size 200kh100, it is possible to use the following code:



<div class = "pretty-image"> </div>


And corresponding CSS:



.pretty-image {background: url (filename.gif); width: 200px; height: 100px}


First it can seem senseless, but actually such way can speed up loading of page much more. In this case the browser will start to load a picture only after the text, instead of simultaneously will be deduced{removed}. Thus users can work with page in who time as the image still will be podgruzhat`sja.


This technics{technical equipment} in the best way approaches for loading only decorative, background elements of page. If the image is a part of contents, all the same it is necessary to use teg IMG.



4. Use of contextual styles


The given code is inefficient:



<p class = "text"> This is a sentence </p> <p class = "text"> This is another sentence </p> <p class = "text"> This is yet another sentence </p> <p class = "text"> This is one more sentence </p> .text {color: *03c; font-size:2em}


Instead of appropriating{giving} a class to each paragraph, they can be grouped in one element DIV with the same class:



<div class = "text"> <p> This is a sentence </p> <p> This is another sentence </p> <p> This is yet another sentence </p> <p> This is one more sentence </p> </div> .text p {color: *03c; font-size:2em}


This code specifies to a browser, that each paragraph inside an element with a class text will have color *03c and the size of a font in 2em.


You could notice, that color here is specified by only three symbols, instead of six. In this case *03c is the reduced spelling of value of color *0033cc.



5. Use of reductions


Font


It is better to write:



font: 1em/1.5em bold italic serif


... Instead of



font-size: 1em;

line-height: 1.5em;

font-weight: bold;

font-style: italic;

font-family: serif


Borders


Better:



border: 1px black solid


... Instead of



border-width: 1px;

border-color: black;

border-style: solid


Background


Write:



background: *fff url (image.gif) no-repeat top left


... Instead of



background-color: *fff;

background-image: url (image.gif);

background-repeat: no-repeat;

background-position: top left;


Spaces and borders


Use:



margin: 2px 1px 3px 4px


(top, to the right, a bottom, to the left)


... Instead of



margin-top: 2px

margin-right: 1px;

margin-bottom: 3px;

margin-right: 4px


Similarly:



margin: 5em 1em 3em


(top, to the left and to the right, a bottom)


... Instead of



margin-top: 5em;

margin-bottom: 1em;

margin-right: 1em;

margin-right: 4em


I:



margin: 5 % of 1 % (top and a bottom, to the left and to the right)


... Instead of



margin-top: 5 %;

margin-bottom: 5 %;

margin-right: 1 %;

margin-right: 1 %


These rules are applied to attributes margin, border and padding.



6. Minimizirovanie blanks, translations of lines and comments


Each symbol - the letter or a blank - borrow{occupy} one byte. Each superfluous symbol only increases the size of pages. Therefore try is smaller to press Enter and Tab during imposition. Besides do not overlook to unite CSS-styles.



7. Use relative links


Absolute links borrow{occupy} much more places, than relative. But also, creates additional loading on a browser that is more important. An example of the absolute link: <a href = " http: // www. URL.com/filename.htm ">. Will write much more correctly <a href = "filename.htm">. But what if the necessary file is in the other catalogue? Some examples which will help you to understand this question:


* <a href = "/"> - the Call of root page of a site http://www.URL.com

* <a href = "/filename.html "> - the Call of page in the root http://www.URL.com/filename.html

* <a href = "/directory/filename.html "> - the File in subdirectory of "root" http://www.URL.com/directory/filename.html

* <a href = ". / "> - the Reference{Manipulation} to the current catalogue and index.html

* <a href = ".. / "> - the Catalogue - parent current and index.html

* <a href = "../filename.html"> - the Same, with the instruction{indication} of a file

* <a href = "../.. / "> - index.html in two catalogues is higher current



8. Be not fond of application tegov META


The majority tegov META sovreshenno unnecessary. If it is interesting, it is possible to look at all existing variants. The most important tegi (keywords and description) are used for optimization of search machines. At use of attribute content in tege META try to not exceed the size in 200 symbols. The big descriptions and set of keywords can be perceived{recognized} by search machines as a spam.



9. Bear{Take out} CSS and JavaScript in separate files


All this know, but not always use. So call CSS from an external file looks:



<link type = "text/css" rel = "stylesheet" href = "filename.css"/>


And accordingly JavaScript:



<script language = "JavaScript" src = "filename.js" type = "text/javascript"> </script>


Any external file gruzitsja all once and then is saved in a local cache. Restrictions on quantity{amount} of "connected" external files does not exist.



10. Put / (slehsh) at the end of links to catalogues


It is a wrong variant of a spelling of the link:



<a href = " http: // www. URL.com/directoryname ">


It is necessary to write so:



<a href = " http: // www. URL.com/directoryname / ">


It speaks very simply. In the first case the browser does not know, on what the link conducts: on a file or the catalogue. "Slehsh" at once lets know, that this link conducts in the catalogue, and necessity for additional check does not arise.



Separate processing single and double a clique of the mouse in swing

Sometimes there is a need{requirement} for separate processing unary and double a clique. For example, we have tree where each element contains chekboks. We want, that the behaviour of a tree was the following: unary cliques should allocate simply an element or remove allocation while double cliques it should be processed by standard image for a tree.


At first sight a problem{task} simple enough, it is possible to make the student of events of the mouse and to use a method getClickCount () class MouseEvent. However thus we collide{face} with an insuperable problem: at unary and double to a clique the method mouseClicked (MouseEvent e) will be always caused that getClickCount () will give out 1. I.e. we cannot say in any way, during the moment to processing of event of the mouse with getClickCount () 1, whether the call of the same event with getClickCount () equal 1 will be equal then.


To solve this problem it is possible with the help javax.swing. Timer. At first some words about this class. This class serves to start one or several actions after the certain interval of expectation. The most valuable property of this class is that actions are carried out in basic stream GUI or a stream of processing of events. How the class starts an additional stream, and we work in a stream to processing of events that imposes some features on realization mnogozadachnosti, we should not think of these features. I.e. we should not think of specificity mnogozadachnosti in swing.


The code of the student of processing of events of the mouse is below resulted.



public class NodeMouseListener extends MouseAdapter {

        private JTree tree;

        private boolean singleClick = true;

        private Timer timer;

        private TreePath path = null;;

        private int row = 0;

             

        private final int delay = 170;


         NodeMouseListener (JTree tree) {

this.tree = tree;

ActionListener al = new ActionListener () {

public void actionPerformed (ActionEvent evt) {

if (singleClick) {

         processSingleClick ();

}

}

};

timer = new javax.swing. Timer (delay, al);

timer.setRepeats (false);

}


public void mouseClicked (MouseEvent e) {

         checkClicks (e);

}


private void checkClicks (MouseEvent e) {

         int x = e.getX ();

int y = e.getY ();

int row = tree.getRowForLocation (x, y);

path = tree.getPathForRow (row);

if (e.getClickCount () == 1) {

         singleClick = true;

         timer.start ();

} else {

         singleClick = false;        

}

}


private void processSingleClick () {        

         if (path! = null) {

                 // We process unary cliques here

}

}



}


This class should be registered in a copy of a class of a tree, as one of students of events of the mouse.


If to pick up delay it is possible to achieve such behaviour of a tree as it is required in a problem{task}.