Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Stylesheet not loading sometimes on some posts #69

Open
t-pabla opened this issue Sep 5, 2017 · 27 comments
Open

Stylesheet not loading sometimes on some posts #69

t-pabla opened this issue Sep 5, 2017 · 27 comments

Comments

@t-pabla
Copy link

t-pabla commented Sep 5, 2017

This is a great simple plugin t use!
However, about four months ago (during 4.7 cycle), I had to deactivate it at my site.

The reason was the theme's stylesheet not working on some posts (randomly), sometimes .

Then I found out if clear the cache of “simple cache” plugins, the stylesheet begins to work fine.

I use child theme of the default twentyten theme.

Is there anyway to find out what might be causing the issue, because I would like to start using this plugin again.

Thanks

@benoitchantre
Copy link
Contributor

This is certainly related to a mixed content situation where the cache was produced by an http request and then reused in an https request. See issue #67.

To prevent that, you need to force https, either using a plugin or a rewrite rule in your .htaccess file.

@t-pabla
Copy link
Author

t-pabla commented Sep 23, 2017

Thanks for the reply, @benoitchantre

When this happened the FIRST time, my site was only http :)

Recently I changed to https. I have already done what you suggested. Still the same problem.

@benoitchantre
Copy link
Contributor

When this happen, open the web inspector of your browser and report back the errors.
This should help to understand why the stylesheet is not loaded.

@t-pabla
Copy link
Author

t-pabla commented Sep 23, 2017

I deactivated the plugin right after my previous reply.

I just activated it again.

Since the issue shows up randomly, I will have to wait until it shows up and then I will be back with the info you asked.

Thanks again so much. Appreciate your time and help

@benoitchantre
Copy link
Contributor

Did you verify that your https redirect work properly? This tool is great https://httpstatus.io

@t-pabla
Copy link
Author

t-pabla commented Sep 23, 2017

Meanwhile, let me ask you if this may be cause of the issue.

I use child theme.

And, I use this method the of Justin Tadlock to enqueue the style: http://justintadlock.com/archives/2014/11/03/loading-parent-styles-for-child-themes

Do you think this might be causing the issue?

@t-pabla
Copy link
Author

t-pabla commented Sep 23, 2017

When I test http://www.example.org/ I get:
Status code 302 -> 200
#redirects 1

FYI, My site works fine, NO error in Google Search Console

As I mentioned before, this issue first showed up when my site was even plain http

@benoitchantre
Copy link
Contributor

benoitchantre commented Sep 23, 2017

I use this method the of Justin Tadlock to enqueue the style: http://justintadlock.com/archives/2014/11/03/loading-parent-styles-for-child-themes

This is the right way to load the parent theme stylesheet.

@t-pabla
Copy link
Author

t-pabla commented Sep 23, 2017

one page randomly up without style. Here are the errors shown in FF console:
Blocked loading mixed active content “http://www.example.com/blog/wp-content/themes/PARENT THEME/style.css?ver=4.8.2”

Blocked loading mixed active content “http://www.example.com/blog/wp-content/themes/CHILD THEME/style.css?ver=4.8.2”

Blocked loading mixed active content “http://www.example.com/blog/wp-content/plugins/zero-spam-gur/zero-spam.min.js?ver=null”

Blocked loading mixed active content “http://www.example.com/blog/wp-includes/js/comment-reply.min.js?ver=4.8.2”

Loading failed for the <script> with source “http://www.example.com/blog/wp-content/plugins/zero-spam-gur/zero-spam.min.js?ver=null”.

Loading failed for the <script> with source “http://www.example.com/blog/wp-includes/js/comment-reply.min.js?ver=4.8.2”.

@benoitchantre
Copy link
Contributor

This is a mixed content situation, browsers don't load your assets in this situation.
You need to use https in the settings and make sure you redirect http to https to prevent that.

@t-pabla
Copy link
Author

t-pabla commented Sep 23, 2017

https in the settings

What I need to do to accomplish it?

Since:

  • I have no problem with my website
  • Google search console does not show any error.
  • I have the following code in my .httaccess:
# redirect http to https
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{SERVER_PORT} 80 
RewriteRule ^(.*)$ https://www.example.com/blog/$1 [R,L]
</IfModule>

are you saying I should also change my WordPress Address (URL) and Site Address (URL) from http to https as well?
Thank you sir, for your help and time







@benoitchantre
Copy link
Contributor

What I need to do to accomplish it?

Check the Site Address and WordPress Address URLs under Settings > General. You should use https.

I just submitted a fix to prevent mixed content, can you test it and let me know if it works for you?

@t-pabla
Copy link
Author

t-pabla commented Sep 25, 2017

Thanks @benoitchantre. appreciate your sincere efforts to help.

A simple thing seems to be working, at least in my case. I'm keeping eye in case the issue randomly shows up again. if does, I will be back.

What I did: After reading here and there, the moved the snippet to redirect http to https RROM bottom of my .htacess to the TOP of my .htaccess. I did not change anything else. Now for couple of days I have not seen that error, YET!

Site Address and WordPress Address URLs under Settings > General. You should use https

No, I left it unchanged --- http

Question: is it for some reason must be changed even though the redirect snippet seems to working without any problems? Thanks.

fix to prevent mixed content, can you test it and let me know if it works for you?

I have not tried it.

@benoitchantre
Copy link
Contributor

Question: is it for some reason must be changed even though the redirect snippet seems to working without any problems? Thanks.

If you use http in your settings, your images will be saved with http URLs instead of https URLs and produce mixed content. The menus items will use http and everything will rely on your redirects. Redirects are great, but they slow down the loading of your website. They should be in place, but used as a fallback.

The patch only work if the settings use https.

@t-pabla
Copy link
Author

t-pabla commented Sep 25, 2017

Great answer! Thanks @benoitchantre !

The patch only work if the settings use https.

Would I still need that redirect snippet in my .htaccess if I use this patch?

Thanks again!

@benoitchantre
Copy link
Contributor

Would I still need that redirect snippet in my .htaccess if I use this patch?

You should keep them, but use 301 redirects (permanent) instead of 302 (temporary) redirects.
The goal of the patch is to prevent mixed content for people who don't force https with redirects but use https in their settings. It is active only if the request is done though http but settings use https.

Can you remove temporary your redirects to https to test the patch?

@t-pabla
Copy link
Author

t-pabla commented Sep 25, 2017

Can you remove temporary your redirects to https to test the patch?

Yes sir.

I'm going to copy the copy the raw simple-cache/inc/dropins/file-based-page-cache-functions.php file and use that one.

And let you how it goes.

You should keep them, but use 301 redirects (permanent) instead of 302 (temporary) redirects.

The code i currently have is this:

# redirect http to https
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{SERVER_PORT} 80 
RewriteRule ^(.*)$ https://www.example.com/blog/$1 [R,L]
</IfModule>

How can I modify it so it becomes 301 redirects (permanent) as you suggested?

Thanks.

@benoitchantre
Copy link
Contributor

How can I modify it so it becomes 301 redirects (permanent) as you suggested?

Use [R=301,L] instead of [R,L].
Browser will remember the redirect (that's why its better to test before with 302).

@t-pabla
Copy link
Author

t-pabla commented Sep 25, 2017

Great! Thanks a lot !

@t-pabla
Copy link
Author

t-pabla commented Sep 25, 2017

something weird when I copy and paste simple-cache/inc/dropins/file-based-page-cache-functions.php

Your raw file shows 232 lines.

However, when I copy and paste, my file shows only 185 lines.

Also, your raw file shows some other modifications which are not in my original file (I use version 1.6.3).
For example, your raw files has } on line 33. However I dont see any "}" in my original file!!
Therefore, My suggestion is if you can attached this file to your next reply. That I can use can copy that file without all these ambiguities.

Thanks.

@benoitchantre
Copy link
Contributor

You can insert the following lines at the line 78.

// Prevent mixed content when there's an http request but the site URL uses https
if ( ! $_SERVER['HTTPS'] && 0 === ( strpos( get_option( 'siteurl' ), 'https' ) ) ) {
	$http_site_url  = str_replace( 'https://', 'http://', get_option( 'siteurl' ) );
	$buffer         = str_replace( $http_site_url, get_option( 'siteurl' ), $buffer );
}

@t-pabla
Copy link
Author

t-pabla commented Sep 25, 2017

Applied that patch.

Also, as you suggested, changed the temporary redirect to permanent redirect.

Now keep checking and let you know how it goes.

Thanks.

@t-pabla
Copy link
Author

t-pabla commented Sep 25, 2017

Applied that patch as you suggested.

Also, as you suggested, changed the temporary redirect to permanent redirect.

I will give you the feed back

@t-pabla
Copy link
Author

t-pabla commented Sep 26, 2017

Thought let you know so far I have not seen any issue !

The test is based on:

  1. Applied that patch as you suggested.
  2. Redirect snippet in .htaccess, but as you suggested, changed the temporary redirect to permanent redirect.

@tlovett1
Copy link
Owner

@benoitchantre thank you for being so helpful. I'll look at the patch.

@t-pabla
Copy link
Author

t-pabla commented Sep 26, 2017

@tlovett1,

Just to let you know, yesterday I also tested with the redirect snippet ALONE (NO patch), and did not see any issue.

In other words, it's possible the the success has nothing to do with the patch.

I did not test the patch without the redirect snippet. Because I was afraid Google may through bunch of 404

@t-pabla
Copy link
Author

t-pabla commented Sep 26, 2017

Since the redirect snippet seems to be working for me, I have removed the patch.

Because, since my redirect snippet is working, I have NO way of reliably testing the patch.

Thanks for your time and help

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

No branches or pull requests

3 participants