SlideShare uma empresa Scribd logo
1 de 27
Baixar para ler offline
DIFFERENCE BETWEEN
     QUERY STRING & HASH




12年6月14日星期四                1
In JavaScript, the fragment identifier of the current HTML or
   XHTML page can be accessed in the "hash" property
   location.hash




12年6月14日星期四                                                       2
Common




12年6月14日星期四   3
• They are both the part of a Uniform
     Resource Locator (URL)
       – http://server/path/program?query_string#fragment_identifier




     Refer: http://en.wikipedia.org/wiki/Query_string
                                                                      4

12年6月14日星期四                                                               4
Difference




12年6月14日星期四     5
delimiter [difference]




12年6月14日星期四                 6
• query string: & = ; ? #
       – ? #: separator and not part of the query string
       – & =: separator and part of the query string
       – field1=value1&field2=value2&field3=value3...
   • fragment identifier : #
       – #: separator and part of the fragment identifiers




     Refer: http://en.wikipedia.org/wiki/Query_string

12年6月14日星期四                                                 7
url encoding[difference]




12年6月14日星期四                   8
depended object [difference]




12年6月14日星期四                       9
• Query string depend on the URI scheme
    – e.g., http: supports queries unlike ftp:.
 • Fragment identifier depend on the document MIME type
    – with different mine type, its effect is different.
    – for MIME text/html pages such as http://www.example.org/
      foo.html#bar the fragment refers to the element with id="bar".
    – for MIME text/plain , http://example.com/
      document.txt#line=10,20 , this example identifies lines 11 through 20 of a
      text document:
    – for MIME application/pdf, http://example.org/doc.pdf#page=35
      will cause Adobe Reader to open the PDF and scroll to page 35




     Refer: http://en.wikipedia.org/wiki/Query_string
                                                                           10

12年6月14日星期四                                                                       10
evaluated object [difference]




12年6月14日星期四                        11
• Query string is evaluated by the server
  • Fragment identifier is evaluated by the
    client (Web browser).
  • url hash不会发送至服务端
  • url hash的变更不会引起网络请求



                                          12

12年6月14日星期四                                    12
use




12年6月14日星期四   13
• query string:
       – can be used to contain the content of an
         HTML form
       – tracking: be passed to the program which
         generates the web page.
           • <a href="frank.html?e0a72cb2a2c7">see my page!</a>
           • <a href="ciccio.html?e0a72cb2a2c7">mine is better</
             a>




     Refer: http://en.wikipedia.org/wiki/Query_string

12年6月14日星期四                                                        14
• fragment identifiers:
       – refers to a resource that is subordinate to another,
         primary resource. The primary resource is identified
         by a Uniform Resource Identifier (URI), and the
         fragment identifier points to the subordinate resource.
       – eg: typically used to identify a portion of that
         document.
       – With the rise of AJAX, some websites use fragment
         identifiers to emulate the back button behavior of
         browsers for page changes that do not require a
         reload, or to emulate subpages.
       – process: first, use hash to memorize the page content
         change; second, use js to analyze the value of hash

    Refer: http://en.wikipedia.org/wiki/Fragment_identifier

12年6月14日星期四                                                       15
• cross-domain pass parameters
       – iframe adaptive height problem when cross
         domain
       – get img url when cross domain




12年6月14日星期四                                          16
function setHash(a){
   !    $.browser.msie?$.locationHash(a):location.hash=a;
   }
   $(window).hashchange(function(){
   !    doHash();
   });
   function doHash(){
   !    var h = location.hash;
            switch (h) {
                  case "#ajax1":
                       ajaxFn1();
                       break;
                  case "#ajax2":
                       ajaxFn2();
                       break;
                  default:
                    $("#ajax").html("哈哈,hash没有啦!");
            }
   }
   function ajaxFn1(){
   !    $("#ajax").load("hi.txt", function(){
   !    !     setHash("#ajax1");
   !    });
   }
   function ajaxFn2(){
   !    $.get("hi.html", function(t){
   !    !     $("#ajax").html(t);
   !    !     setHash("#ajax2");
   !    });
   }




12年6月14日星期四                                                 17
• apply kissy mvc router in shop
     category manager
       – url: siteadmin.daily.taobao.net/category/
         auction.htm?sid=12203#!search?catId=-1
       – why use #! ? It is suggest by google
       – refer: support.google.com/webmasters/bin/
         answer.py?hl=en&answer=174992




12年6月14日星期四                                          18
– examples:
          • kissy, mvc, router
          • Gmail uses a single URL for almost every interface – mail boxes,
            individual mails, search results, settings – the fragment is used to
            make these interfaces directly linkable.[6]
          • Adobe Flash websites can use the fragment part to inform the user
            about the state of the website or web application, and to facilitate
          • deep linking, commonly with the help of the SWFAddress JavaScript
            library.
          • Other websites use the fragment part to pass some extra information
            to scripts running on them – for example, Google Video understands
            permalinks in the format of #01h25m30s to start playing at the
            specified position,[7] and YouTube uses similar code such as
            #t=3m25s.[8] A format of #t=10,20 for a section of media from 10
            to 20 seconds is proposed in the Media Fragments URI 1.0 W3C
            Working Draft.[9]




12年6月14日星期四                                                                        19
does url length has impact on
   page load speed?




12年6月14日星期四                        20
第一等级的优化,70字节
    如何计算的呢?




                  21

12年6月14日星期四            21
Refer: http://blog.csdn.net/aimingoo/article/details/6081964 - ncz
                                                                          22

12年6月14日星期四                                                                    22
what http header include?




                               23

12年6月14日星期四                         23
• http 请求头部信息




12年6月14日星期四        24
•    资源文件的get请求http头部的最大长度是496字节
   •    http头部包含两大部分:
         ★ 可缺省的: 占 184字节
         ★ 必须的:占496-184 = 312字节, 包含:get , user-agent, cookie
             ‣ 其中cookie可被缓存,所以相当与长度为0字节
             ‣ user-agent的长度在214字节左右
             ‣ 故剩下get部分的长度 = 496-214-78个字节
   •    这么做的效果:当我们总是从浏览器端发出最小化的HTTP请求时,网络总是可以最快速的将请求提
        交到服务器,无需等待多个包并组合。这在慢速网络,以及存在大量丢包的网络中效果将为极为明
        显。简单地说,如果有人在局域网中用迅雷或BT,那么最小化HTTP请求将会使网页的浏览体验提升
        得相当相当明显。




       Refer: http://blog.csdn.net/aimingoo/article/details/6081964 - ncz

12年6月14日星期四                                                                 25
use




12年6月14日星期四   26
• But with 78 bytes url, what we can do is very little. One
     common url is longer than this length.
   • eg: http://assets.daily.taobao.net/apps/taesite/platinum/
     scripts/common/mods/shop/custom-banner/custom-
     banner.js (109 bytes)




12年6月14日星期四                                                      27

Mais conteúdo relacionado

Destaque

Google I/O 2011, Android Honeycomb Highlights
Google I/O 2011, Android Honeycomb HighlightsGoogle I/O 2011, Android Honeycomb Highlights
Google I/O 2011, Android Honeycomb HighlightsRomain Guy
 
Drug metabolism ppt
Drug metabolism pptDrug metabolism ppt
Drug metabolism pptSameera Sam
 
Allopurinol drug information
Allopurinol drug informationAllopurinol drug information
Allopurinol drug informationSneha Gogineni
 
Strategy, Investment and New Services Development Path in Retail Industry by ...
Strategy, Investment and New Services Development Path in Retail Industry by ...Strategy, Investment and New Services Development Path in Retail Industry by ...
Strategy, Investment and New Services Development Path in Retail Industry by ...Özcan Çavuşoğlu, Ph.D.(Cand.)
 
Hunting Unicorns - What makes an effective UX Professional
Hunting Unicorns - What makes an effective UX ProfessionalHunting Unicorns - What makes an effective UX Professional
Hunting Unicorns - What makes an effective UX ProfessionalPatrick Neeman
 
Sunny Days Ahead
Sunny Days AheadSunny Days Ahead
Sunny Days AheadEAI
 
Mathematics anxiety 1
Mathematics anxiety 1Mathematics anxiety 1
Mathematics anxiety 1onearbaein
 
Seminar on human resource management
Seminar on human resource managementSeminar on human resource management
Seminar on human resource managementBibin Ssb
 
12 Reasons to use YouTube in schools and organizations.
12 Reasons to use YouTube in schools and organizations.12 Reasons to use YouTube in schools and organizations.
12 Reasons to use YouTube in schools and organizations.EduTechNia
 
Think global act local an interview with csoft ceo shunee yee
Think global act local an interview with csoft ceo shunee yeeThink global act local an interview with csoft ceo shunee yee
Think global act local an interview with csoft ceo shunee yeeJia Liu
 
MSX1 Polymorphism in an Eastern Nepalese Non Syndromic cleft lip/palate patie...
MSX1 Polymorphism in an Eastern Nepalese Non Syndromic cleft lip/palate patie...MSX1 Polymorphism in an Eastern Nepalese Non Syndromic cleft lip/palate patie...
MSX1 Polymorphism in an Eastern Nepalese Non Syndromic cleft lip/palate patie...Ashok Ayer
 

Destaque (20)

Annual return
Annual returnAnnual return
Annual return
 
The Top Newsmakers
The Top NewsmakersThe Top Newsmakers
The Top Newsmakers
 
System design
System designSystem design
System design
 
Google I/O 2011, Android Honeycomb Highlights
Google I/O 2011, Android Honeycomb HighlightsGoogle I/O 2011, Android Honeycomb Highlights
Google I/O 2011, Android Honeycomb Highlights
 
Facebook portal
Facebook portalFacebook portal
Facebook portal
 
Official Elisa Powerpoint
Official Elisa PowerpointOfficial Elisa Powerpoint
Official Elisa Powerpoint
 
Internet History
Internet HistoryInternet History
Internet History
 
Drug metabolism ppt
Drug metabolism pptDrug metabolism ppt
Drug metabolism ppt
 
Motivation
MotivationMotivation
Motivation
 
Allopurinol drug information
Allopurinol drug informationAllopurinol drug information
Allopurinol drug information
 
Strategy, Investment and New Services Development Path in Retail Industry by ...
Strategy, Investment and New Services Development Path in Retail Industry by ...Strategy, Investment and New Services Development Path in Retail Industry by ...
Strategy, Investment and New Services Development Path in Retail Industry by ...
 
Spread of infection
Spread of infectionSpread of infection
Spread of infection
 
Hunting Unicorns - What makes an effective UX Professional
Hunting Unicorns - What makes an effective UX ProfessionalHunting Unicorns - What makes an effective UX Professional
Hunting Unicorns - What makes an effective UX Professional
 
Sunny Days Ahead
Sunny Days AheadSunny Days Ahead
Sunny Days Ahead
 
Mathematics anxiety 1
Mathematics anxiety 1Mathematics anxiety 1
Mathematics anxiety 1
 
Seminar on human resource management
Seminar on human resource managementSeminar on human resource management
Seminar on human resource management
 
How to keep stress from running your life
How to keep stress from running your lifeHow to keep stress from running your life
How to keep stress from running your life
 
12 Reasons to use YouTube in schools and organizations.
12 Reasons to use YouTube in schools and organizations.12 Reasons to use YouTube in schools and organizations.
12 Reasons to use YouTube in schools and organizations.
 
Think global act local an interview with csoft ceo shunee yee
Think global act local an interview with csoft ceo shunee yeeThink global act local an interview with csoft ceo shunee yee
Think global act local an interview with csoft ceo shunee yee
 
MSX1 Polymorphism in an Eastern Nepalese Non Syndromic cleft lip/palate patie...
MSX1 Polymorphism in an Eastern Nepalese Non Syndromic cleft lip/palate patie...MSX1 Polymorphism in an Eastern Nepalese Non Syndromic cleft lip/palate patie...
MSX1 Polymorphism in an Eastern Nepalese Non Syndromic cleft lip/palate patie...
 

Semelhante a difference between query string and hash

高性能网站最佳实践
高性能网站最佳实践高性能网站最佳实践
高性能网站最佳实践longhao
 
[2008]网站重构 -who am i
[2008]网站重构 -who am i[2008]网站重构 -who am i
[2008]网站重构 -who am iTwinsen Liang
 
4. Go 工程化实践-0124-v2.pdf
4. Go 工程化实践-0124-v2.pdf4. Go 工程化实践-0124-v2.pdf
4. Go 工程化实践-0124-v2.pdfssuserd6c7621
 
Html5和css3入门
Html5和css3入门Html5和css3入门
Html5和css3入门Xiujun Ma
 
HTML5概览
HTML5概览HTML5概览
HTML5概览Adam Lu
 
基于Greasemonkey的Firefox浏览器扩展
基于Greasemonkey的Firefox浏览器扩展基于Greasemonkey的Firefox浏览器扩展
基于Greasemonkey的Firefox浏览器扩展agen
 
移动端Web开发性能优化实践
移动端Web开发性能优化实践移动端Web开发性能优化实践
移动端Web开发性能优化实践Mingel Zhang
 
网页制作基础
网页制作基础网页制作基础
网页制作基础loo2k
 
Inside the-browser
Inside the-browserInside the-browser
Inside the-browserjy03845581
 
Inside the-browser
Inside the-browserInside the-browser
Inside the-browserjy03845581
 
非常靠谱 Html 5
非常靠谱 Html 5 非常靠谱 Html 5
非常靠谱 Html 5 Tony Deng
 
Exam 98-375 HTML5 Application Development Fundamentals
Exam 98-375 HTML5 Application Development FundamentalsExam 98-375 HTML5 Application Development Fundamentals
Exam 98-375 HTML5 Application Development FundamentalsChieh Lin
 
前端性能测试
前端性能测试前端性能测试
前端性能测试tbmallf2e
 
浅析浏览器解析和渲染
浅析浏览器解析和渲染浅析浏览器解析和渲染
浅析浏览器解析和渲染Ailsa126
 
開放原始碼 Ch2.5 app - oss - 3rd party api(ver 1.0)
開放原始碼 Ch2.5   app - oss - 3rd party api(ver 1.0) 開放原始碼 Ch2.5   app - oss - 3rd party api(ver 1.0)
開放原始碼 Ch2.5 app - oss - 3rd party api(ver 1.0) My own sweet home!
 
网页制作基础
网页制作基础网页制作基础
网页制作基础loo2k
 
資料結構化專家會議簡報 V1.3 20160628
資料結構化專家會議簡報 V1.3 20160628資料結構化專家會議簡報 V1.3 20160628
資料結構化專家會議簡報 V1.3 20160628Poya Liao
 
Inside the browser
Inside the browserInside the browser
Inside the browserotakustay
 
基于Greasemonkey的Firefox浏览器扩展
基于Greasemonkey的Firefox浏览器扩展基于Greasemonkey的Firefox浏览器扩展
基于Greasemonkey的Firefox浏览器扩展agen
 

Semelhante a difference between query string and hash (20)

Html5
Html5Html5
Html5
 
高性能网站最佳实践
高性能网站最佳实践高性能网站最佳实践
高性能网站最佳实践
 
[2008]网站重构 -who am i
[2008]网站重构 -who am i[2008]网站重构 -who am i
[2008]网站重构 -who am i
 
4. Go 工程化实践-0124-v2.pdf
4. Go 工程化实践-0124-v2.pdf4. Go 工程化实践-0124-v2.pdf
4. Go 工程化实践-0124-v2.pdf
 
Html5和css3入门
Html5和css3入门Html5和css3入门
Html5和css3入门
 
HTML5概览
HTML5概览HTML5概览
HTML5概览
 
基于Greasemonkey的Firefox浏览器扩展
基于Greasemonkey的Firefox浏览器扩展基于Greasemonkey的Firefox浏览器扩展
基于Greasemonkey的Firefox浏览器扩展
 
移动端Web开发性能优化实践
移动端Web开发性能优化实践移动端Web开发性能优化实践
移动端Web开发性能优化实践
 
网页制作基础
网页制作基础网页制作基础
网页制作基础
 
Inside the-browser
Inside the-browserInside the-browser
Inside the-browser
 
Inside the-browser
Inside the-browserInside the-browser
Inside the-browser
 
非常靠谱 Html 5
非常靠谱 Html 5 非常靠谱 Html 5
非常靠谱 Html 5
 
Exam 98-375 HTML5 Application Development Fundamentals
Exam 98-375 HTML5 Application Development FundamentalsExam 98-375 HTML5 Application Development Fundamentals
Exam 98-375 HTML5 Application Development Fundamentals
 
前端性能测试
前端性能测试前端性能测试
前端性能测试
 
浅析浏览器解析和渲染
浅析浏览器解析和渲染浅析浏览器解析和渲染
浅析浏览器解析和渲染
 
開放原始碼 Ch2.5 app - oss - 3rd party api(ver 1.0)
開放原始碼 Ch2.5   app - oss - 3rd party api(ver 1.0) 開放原始碼 Ch2.5   app - oss - 3rd party api(ver 1.0)
開放原始碼 Ch2.5 app - oss - 3rd party api(ver 1.0)
 
网页制作基础
网页制作基础网页制作基础
网页制作基础
 
資料結構化專家會議簡報 V1.3 20160628
資料結構化專家會議簡報 V1.3 20160628資料結構化專家會議簡報 V1.3 20160628
資料結構化專家會議簡報 V1.3 20160628
 
Inside the browser
Inside the browserInside the browser
Inside the browser
 
基于Greasemonkey的Firefox浏览器扩展
基于Greasemonkey的Firefox浏览器扩展基于Greasemonkey的Firefox浏览器扩展
基于Greasemonkey的Firefox浏览器扩展
 

difference between query string and hash

  • 1. DIFFERENCE BETWEEN QUERY STRING & HASH 12年6月14日星期四 1
  • 2. In JavaScript, the fragment identifier of the current HTML or XHTML page can be accessed in the "hash" property location.hash 12年6月14日星期四 2
  • 4. • They are both the part of a Uniform Resource Locator (URL) – http://server/path/program?query_string#fragment_identifier Refer: http://en.wikipedia.org/wiki/Query_string 4 12年6月14日星期四 4
  • 7. • query string: & = ; ? # – ? #: separator and not part of the query string – & =: separator and part of the query string – field1=value1&field2=value2&field3=value3... • fragment identifier : # – #: separator and part of the fragment identifiers Refer: http://en.wikipedia.org/wiki/Query_string 12年6月14日星期四 7
  • 10. • Query string depend on the URI scheme – e.g., http: supports queries unlike ftp:. • Fragment identifier depend on the document MIME type – with different mine type, its effect is different. – for MIME text/html pages such as http://www.example.org/ foo.html#bar the fragment refers to the element with id="bar". – for MIME text/plain , http://example.com/ document.txt#line=10,20 , this example identifies lines 11 through 20 of a text document: – for MIME application/pdf, http://example.org/doc.pdf#page=35 will cause Adobe Reader to open the PDF and scroll to page 35 Refer: http://en.wikipedia.org/wiki/Query_string 10 12年6月14日星期四 10
  • 12. • Query string is evaluated by the server • Fragment identifier is evaluated by the client (Web browser). • url hash不会发送至服务端 • url hash的变更不会引起网络请求 12 12年6月14日星期四 12
  • 14. • query string: – can be used to contain the content of an HTML form – tracking: be passed to the program which generates the web page. • <a href="frank.html?e0a72cb2a2c7">see my page!</a> • <a href="ciccio.html?e0a72cb2a2c7">mine is better</ a> Refer: http://en.wikipedia.org/wiki/Query_string 12年6月14日星期四 14
  • 15. • fragment identifiers: – refers to a resource that is subordinate to another, primary resource. The primary resource is identified by a Uniform Resource Identifier (URI), and the fragment identifier points to the subordinate resource. – eg: typically used to identify a portion of that document. – With the rise of AJAX, some websites use fragment identifiers to emulate the back button behavior of browsers for page changes that do not require a reload, or to emulate subpages. – process: first, use hash to memorize the page content change; second, use js to analyze the value of hash Refer: http://en.wikipedia.org/wiki/Fragment_identifier 12年6月14日星期四 15
  • 16. • cross-domain pass parameters – iframe adaptive height problem when cross domain – get img url when cross domain 12年6月14日星期四 16
  • 17. function setHash(a){ ! $.browser.msie?$.locationHash(a):location.hash=a; } $(window).hashchange(function(){ ! doHash(); }); function doHash(){ ! var h = location.hash; switch (h) { case "#ajax1": ajaxFn1(); break; case "#ajax2": ajaxFn2(); break; default: $("#ajax").html("哈哈,hash没有啦!"); } } function ajaxFn1(){ ! $("#ajax").load("hi.txt", function(){ ! ! setHash("#ajax1"); ! }); } function ajaxFn2(){ ! $.get("hi.html", function(t){ ! ! $("#ajax").html(t); ! ! setHash("#ajax2"); ! }); } 12年6月14日星期四 17
  • 18. • apply kissy mvc router in shop category manager – url: siteadmin.daily.taobao.net/category/ auction.htm?sid=12203#!search?catId=-1 – why use #! ? It is suggest by google – refer: support.google.com/webmasters/bin/ answer.py?hl=en&answer=174992 12年6月14日星期四 18
  • 19. – examples: • kissy, mvc, router • Gmail uses a single URL for almost every interface – mail boxes, individual mails, search results, settings – the fragment is used to make these interfaces directly linkable.[6] • Adobe Flash websites can use the fragment part to inform the user about the state of the website or web application, and to facilitate • deep linking, commonly with the help of the SWFAddress JavaScript library. • Other websites use the fragment part to pass some extra information to scripts running on them – for example, Google Video understands permalinks in the format of #01h25m30s to start playing at the specified position,[7] and YouTube uses similar code such as #t=3m25s.[8] A format of #t=10,20 for a section of media from 10 to 20 seconds is proposed in the Media Fragments URI 1.0 W3C Working Draft.[9] 12年6月14日星期四 19
  • 20. does url length has impact on page load speed? 12年6月14日星期四 20
  • 21. 第一等级的优化,70字节 如何计算的呢? 21 12年6月14日星期四 21
  • 23. what http header include? 23 12年6月14日星期四 23
  • 25. 资源文件的get请求http头部的最大长度是496字节 • http头部包含两大部分: ★ 可缺省的: 占 184字节 ★ 必须的:占496-184 = 312字节, 包含:get , user-agent, cookie ‣ 其中cookie可被缓存,所以相当与长度为0字节 ‣ user-agent的长度在214字节左右 ‣ 故剩下get部分的长度 = 496-214-78个字节 • 这么做的效果:当我们总是从浏览器端发出最小化的HTTP请求时,网络总是可以最快速的将请求提 交到服务器,无需等待多个包并组合。这在慢速网络,以及存在大量丢包的网络中效果将为极为明 显。简单地说,如果有人在局域网中用迅雷或BT,那么最小化HTTP请求将会使网页的浏览体验提升 得相当相当明显。 Refer: http://blog.csdn.net/aimingoo/article/details/6081964 - ncz 12年6月14日星期四 25
  • 27. • But with 78 bytes url, what we can do is very little. One common url is longer than this length. • eg: http://assets.daily.taobao.net/apps/taesite/platinum/ scripts/common/mods/shop/custom-banner/custom- banner.js (109 bytes) 12年6月14日星期四 27