Write JS and CSS in the same file writing method _javascript skills

Source: Internet
Author: User
We often put multiple CSS or multiple JS into one, to save the request, but this is at least two. On the MSDN blog to see the original is also can be JS and CSS and in a file, then how to do it? Using annotations, look at the code first.
<!--/*
Window.onload=function () {
document.getElementById ("Test2"). Innerhtml= "The legendary drop of JS tester. If you see me, that <strong>JS</strong> also takes effect ";
}
<!--* *
<!--#test1, #test2 {border:3px #000 solid;padding:5px;color: #123456; Background-color: #ccc;} strong{color:red;}

CSS processing will ignore <!--, at this time JS part is just CSS annotation/js * *, and JS processing <!--into/or JS is a single line of comments, a single note will be behind the/* and * * kill, but also killed the CSS, no nonsense, see the demonstration examples.

In the online operation also to pass the program output a "*/*" head, or MIME is not the browser does not work. PHP is the case:

<?header (' Content-type: */* ');? >

In theory, a mime that specifies a suffix on the server is a "*/*" application, but I didn't try. To write JS and CSS in the same file is particularly suitable for third-party calls, although the file is a bit large, but can be less than half of the request number, handsome drop

Of course, such a format must be very unpleasant to write, but with the program to read the original already, and deal with it, so you can keep the original file is also convenient maintenance, output file and save the request, if you want to, processing processing cache, with the static file almost. Here is a C #, is said to be the official drop, I am PHP, because the mechanism has not been written to the cache will not take out the shame, in fact, the principle is very simple, will be programmed 32 under the fix.

In fact, I want to find a number of CSS merged way, synthesis of a not difficult, can be handled by the separation of the modules at the same time in the client cache and convenient program calls is difficult, CSS and unlike JS can be invoked in the client asynchronous, who has a good way to introduce to me.

The legendary test
The legendary tester number one. If you see me with a border and a color, that means that CSS is in effect.

The legend drops JS tester. If you see me, that JS is also in effect.

Copy Code code as follows:
Use the same file:jscss.php 
<link type= text/css " rel=" Stylesheet " href=" jscss.php " /><script type=" Text/javascript " src=" jscss.php "> </script>jscss.php content  
<?header (' content-type: */* ');? > 
<!-- /* 
Window.onload=function () { 
     document.getElementById ("Test2"). Innerhtml= "The legendary drop of JS tester. If you see me, then <strong>JS</strong> also takes effect. "; 

<!-- */  
<!--  #test1, #test2 {border:3px  #000  solid;padding:5px;color: #123456; Background-color: #ccc;}  strong{color:red;}  
copyright © 2006-2007 aoao , some rights reserved . 
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.