>您现在的位置:文学月刊 > 西方诗歌

Combine CSS with JS and make it into a single download! – My experiments with .Net

2019-08-13 11:59作者:admin

Combine CSS with JS and make it into a single download! – My experiments with .Net

Now,ifyouhavebyanychanceworkedonpageloadoptimizations,,,webpagesref(pageloadtime)gurusistocombinealltheCSSfilesintooneandallthe,withoutanydoubt,tthebest,,welllookatatechniquetocombineCSSwithJSandgettheresourcedownloadcounttoone!Idiscoveredthistechn..(!--)inCSScontent,(!--)inJScontent,thetokenistreatedsimilartothelinecomment(//)andhencetherestofthelinefollowingtheHTMLcommenttokengetsignoredLookatthebelowJS+CSScodesnippet...!--/*functiont(){}!--*/!--body{background-color:Aqua;}WhentheCSSparserparsestheabovecontent,theHTMLcommenttokenswouldbedroppedandthesnippetwouldbecomeequivalenttotheonebelow.../*functiont(){}*/body{background-color:Aqua;}Asyoucanseeabove,theCSSparserwillgettoseeonlytheCSScodeandthescriptcodewouldappeartobewithinthecomments(/*...*/).Insimilarlines,whentheJSparserparsesthecontent,theHTMLcommenttokenswouldbetreatedaslinecomments(//)andhencethecodesnippetwouldbecomeequivalenttotheonebelow...///*functiont(){}//*///body{background-color:Aqua;}Asyoucanseeabove,theJSparserwillgettos,linktype="text/css"rel="stylesheet"href=""/scripttype="text/javascript"language="javascript"src=""/scriptNoteabovethatboththetagsrefertothesamesourceandhenceitwouldbedownloadedonceandusedasappropriate(asCSSandSCRIPT).Torounditoff,thereisjustonemorethingthatyouneedtotakecareof-theresponsecontenttype-itneedstobesetto*/*inordertoafveattachedasampleproject(createdwithVS2005SP1)!Update:(putinplaceduetopopularmisconception)Inthe,youllhavetocombinethembyaddingtheHTMLcommentcompromiseonthereadability,(s):IftheJScontainsanymultilinecomme,:|||||。

随机推荐

图文聚集

热门排行

最新文章