HTML5微数据:如何防止通过微数据增加文件大小

时间:2012-05-25 14:43:50

标签: performance html5 compression metadata microdata

目前,我将schema.org Microdata添加到了我的页面。我没有使用<meta>添加隐藏内容,我只是在页面内容上使用它,在那里我可以找到合适的schema.org词汇表。但是现在我文件的gzip压缩版本的大小增加了11%,正常版本的大小增加了24%。

对于目前仅被某些搜索机器人使用的标记来说,这显然太多了。这就是我想到c14n的原因。我知道这可能不是最好的方式,但我想创建一个带有Microdata的版本和一个没有Microdata的版本,然后我使用HTTP Link: <http://www.example.com/>; rel="canonical"将它们链接在一起。

我的问题:

  1. 使用c14n解决问题你有什么看法。
  2. 是否有更好的方法可以在不增加的情况下添加高级元数据 大小那么多?

1 个答案:

答案 0 :(得分:0)

  1. 我认为规范化不会起作用。使用<link rel="canonical href="microdatversion">基本上会告诉机器人索引微数据版本及其所有微数据(好)。但它也会对查询结果进行排名,这会将用户带到微数据版本(坏)。
  2. 我会编写一个脚本来添加所有的微数据。显然推迟了脚本加载。 您可以将属性添加为类名,如下所示。

    <div class="it-p is ip-d"></div>

    <script defer>
  3. 
    function shortHand(type, cName)
    {
        if(type ==='itemprop')
        {
            switch(cName)
            {
             case 'n': return 'name';
             break;
             case 'd': return 'description'
             break;
             default:  return cName;
             }
        }
        if(type==='itemtype')
        {
            switch(cName)
            {
            case 'p': return 'Product';
            break;
            default : return cName;
            }
        }
    
    }
    function addItemprop(el,cName)
    {
        cName = shortHand('itemprop', cName);
        el.setAttribute('itemprop',cName)
    }
    function addItemtype(el,cName)
    {
        cName = shortHand('itemtype', cName);
        el.setAttribute('itemtype','http://scheme.org/'+cName)
    }
    
    $('[class]').filter(function()
    {
        var removeclass=[];
    
        for(var i=0; i < this.classList.length; i++) 
        {
            var cName =this.classList[i];
            if (/^ip-/.test(cName))addItemprop(this,cName.replace('ip-',''));removeclass.push(cName);
            if (cName =='is')removeclass.push(cName);this.setAttribute('itemscope','');
            if (/^it-/.test(cName))addItemtype(this,cName.replace('it-',''));removeclass.push(cName);
    
        }
        for(var i=0; i < removeclass.length; i++) 
        {
            this.classList.remove(removeclass[i]);
        }
    });