代码之家  ›  专栏  ›  技术社区  ›  Gajus

preload=“true”超链接

  •  0
  • Gajus  · 技术社区  · 16 年前

    http://ahostel.lt/

    4 回复  |  直到 10 年前
        1
  •  1
  •   Malabar Front    16 年前

    HTML5规范中实际上对此有规定,尽管目前只有Firefox支持。

    <link rel="next" href="page2.html">
    

    把它作为一个非javascript的替代品扔给你。

        2
  •  2
  •   Pointy    16 年前

    你可以这样做:

    $(function() {
      $('a').each(function() {
        new Image().src = $(this).attr('href'); // or just this.href
      });
    });
    

    它们不是图像,但浏览器不知道。您可能需要将速度减慢一点,以免过度阻塞连接:

    $(function() {
      var urls = $('a').map(function(_, a) { return a.href; }).get(0);
      var i = 0;
      function fetchOne() {
        if (i === urls.length) return;
        var img = new Image();
        img.load = fetchOne;
        img.src = urls[i++];
      };
      fetchOne();
    });
    

    -@Adam对获取“危险”链接提出了非常好的观点。最好将一些链接标记为“noPrefetch”(作为一个类或其他东西),或者只预取链接显式标记为类“prefetch”。

        3
  •  1
  •   Adam    16 年前

    没有尝试过,但基于 this blog post ,可以执行以下操作:

    $("a").each(function(){
      $.ajax({ url:$(this).attr("href"), cache:true, dataType:"text" });
    });
    

    你应该小心,如果你有像注销用户可能会注销链接。 See Wikipedia for more problems with prefetching .