Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

HTML Compressor unable to compress application/ld+json #467

Closed
isaumya opened this issue Apr 15, 2015 · 4 comments
Closed

HTML Compressor unable to compress application/ld+json #467

isaumya opened this issue Apr 15, 2015 · 4 comments

Comments

@isaumya
Copy link

isaumya commented Apr 15, 2015

Hi, recently I've discovered a slight pitfall of Zencache Pro HTML Compressor with <script type="application/ld+json"> internal script tag. Beside I must admit that this is the best HTML compressor I've ever seen or used anywhere else. Anyways, in my site I use application/ld+json tag for some schema.org markups and hense I've created this small function:

//* scripts on footer
function ism_script_in_footer() {
    if ( is_front_page() ) :
        echo '<script type="application/ld+json">
{ 
    "@context": "http://schema.org",
    "@type": "WebSite",
    "url": "https://www.isaumya.com/",
    "potentialAction": {
        "@type": "SearchAction","target": "https://www.isaumya.com/?s={search_term}",
        "query-input": "required name=search_term"
    },
    "creator" : {
        "@type": "Person",
        "name": "Saumya Majumder",
        "url": "https://www.isaumya.com",
        "sameAs": ["https://www.facebook.com/iamSaumya",
        "https://twitter.com/iSaumya",
        "https://github.com/isaumya",
        "https://plus.google.com/+SaumyaMajumder",
        "http://in.linkedin.com/in/saumyamajumder",
        "https://www.youtube.com/user/iSaumyaM"
        ],
        "makesOffer" : {
            "@type" : "Offer",
            "itemOffered" : [
            {
                "@type" : "Product",
                "name" : "Web Development"
            },
            {
                "@type" : "Product",
                "name" : "WordPress Optimization"
            },
            {
                "@type" : "Product",
                "name" : "Fusioninvoice Customization"
            },
            {
                "@type" : "Product",
                "name" : "Web Consultation"
            },
            {
                "@type" : "Product",
                "name" : "Search Engine Optimization"
            },
            {
                "@type" : "Product",
                "name" : "WordPress Customization"
            }
            ]
        }
    }
}   
</script>';
endif;
}
add_filter( 'wp_footer', 'ism_script_in_footer', 99 );

Now this is working fine but after activating HTML Compressor of Zencache pro if you check the source code of the site, you will see that everything is properly compressed except that <script type="application/ld+json">. Here is a screenshot:

2015-04-15_17-13-15

Looking forward to hear your insight on this.

@raamdev
Copy link
Contributor

raamdev commented Apr 16, 2015

@raamdev raamdev closed this as completed Apr 16, 2015
@raamdev
Copy link
Contributor

raamdev commented Apr 16, 2015

@isaumya If you'd like that script to be compressed, I recommend compressing it before adding it to your function. You can use a tool like this: http://jsfail.com/tools/JsonMinify.html

{"@context":"http://schema.org","@type":"WebSite","url":"https://www.isaumya.com/","potentialAction":{"@type":"SearchAction","target":"https://www.isaumya.com/?s={search_term}","query-input":"required name=search_term"},"creator":{"@type":"Person","name":"Saumya Majumder","url":"https://www.isaumya.com","sameAs":["https://www.facebook.com/iamSaumya","https://twitter.com/iSaumya","https://github.com/isaumya","https://plus.google.com/+SaumyaMajumder","http://in.linkedin.com/in/saumyamajumder","https://www.youtube.com/user/iSaumyaM"],"makesOffer":{"@type":"Offer","itemOffered":[{"@type":"Product","name":"Web Development"},{"@type":"Product","name":"WordPress Optimization"},{"@type":"Product","name":"Fusioninvoice Customization"},{"@type":"Product","name":"Web Consultation"},{"@type":"Product","name":"Search Engine Optimization"},{"@type":"Product","name":"WordPress Customization"}]}}}

@raamdev
Copy link
Contributor

raamdev commented Apr 16, 2015

@isaumya I've opened a feature request to add JSON compression support here: #469

@isaumya
Copy link
Author

isaumya commented Apr 16, 2015

Thank you @raamdev for opening the feature request. Looking forward to it.
The main reason, I don't wanna add minified JSON inside website code is because, it will become hard to edit the code if needed in future. At that moment, I have to de-minify it and then edit it and then again minify it. Its better to be added inside the zencahe pro.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants