开发者 | majick |
---|---|
更新时间 | 2022年8月29日 12:03 |
捐献地址: | 去捐款 |
PHP版本: | 3.0.0 及以上 |
WordPress版本: | 6.0 |
版权: | GPLv2 or later |
版权网址: | 版权信息 |
<img>
elements) - comparitively pretty easy!<link rel='stylesheet'>
elements) - pretty tricky!
(and yes it can check and reload stylesheets in Firefox!)<style>
elements (possible)<script src='somescript.js'>
elements) - difficult!
Not Working yet (workarounds in progress) for:<iframe src='somepage.html'>
elements) - near impossible!wp-automedic.zip
via the Plugins upload page.<style>
elements?Ideally, you wouldn't need this as your page loads fine every time... but of course,
that is not always the case, hence the need for this plugin in the first place. So
most of the time you probably won't notice WP AutoMedic is actually doing anything,
but like a medic should be, it is on standby in case of emergencies, and firing your
medic (deactivating the plugin) just because you are not injured ("but my pages are
loading fine!") may not be the best idea when you don't have to (this plugin is free.)
However, you may want to make sure the medic is well trained (that this plugin actually
works and does what it says) and so do a training exercise. The testing of this
plugin script particularly tricky, simply because most of the time your page DOES
load fine! So to truly know and test this plugin is working correctly (rather than
just the page is loading correctly - ie. no injury) we need to set up a fake page
with some broken resources (simulate an injury) and then look at that with AutoMedic
loaded and see exactly what happens...
To that end, you can test WP AutoMedic by putting the [automedic-test]
shortcode on
a new post or page - optionally save as a draft for later - and then click on Preview
Post. The output of the shortcode simulates a number of broken resources in the content
area so that you can see the results. You can also check the browser console log to see
all the AutoMedic events that are logged there along ith all those lovely lines of
red broken resources. Keep in mind that the output and result can be different in
different browsers and test those if you like. You can adjust the plugin settings
(elements to reload and reload times etc on the settings page) and reload the page
again to check it, and further adjust to suit your liking.
You can set the reloading for each type of supported resource to run on the Front End, Back End (Admin Area) of your site - or both - or neither... Minimum recommended setting is Front End loading for both images and stylesheets.
Yes, definitely. First, this is never going to be perfect. Depending on which browser is used and what it's particular limitations are, the AutoMedic script may fail in part or entirely, if the browser does not have the needed browser support to do what it needs. (But, this could be said for just about any script and supporting older browsers has always been a web developer's nightmare.) On the other hand, AutoMedic was written with this kept in mind specifically from the start, so the needed functions have been kept to a bare minimum of very commonly supported Javascript-only usage (not jQuery, even though the whole thing would have been much easier to write in jQuery!) and checks are in place for even thosee remotely unsupported functions used, so as to make sure it works most of the time and can fallback (or rather, failback) to doing nothing if the support really isn't there. As it improves and adds more checks like this, it will work better across more browsers. For a more specific list of limitations and issues, see Other Notes section.
Yes. Depending on the CDN it may or may not limit what AutoMedic can check and reload, as some resources may be considered 'cross-domain' due to this. Specifically that is, for stylesheets, that depending on the domain they are loaded from they may be treated as external stylesheets if the resource URL is for a CDN on another domain. There are workarounds in place for external stylesheets however, so read that section for more details.
The short answer is no. The longer answer is 'not yet!' WP AutoMedic is written in
pure Javascript rather than jQuery to increase it's chance of success and also so it
can be released as a standalone minimal script for other CMS and website platforms -
or basically for any HTML page in the future so the basic functions work just by adding
an automedic.js
script to the page (currently image and stylesheet reloading.)
The more advanced features will more than likely require a little more setup with the
standalone version to get working as it may require buffering the entire page output.
(WP AutoMedic can do this already for example using the WordpPress hooks.) To begin with
however, the Wordpress plugin version will be used for development and testing of a
standalone version. (The WP version will probably always have more features as it is
able to hook into the existing Wordpress settings, action hooks and page content much
more easily and provide a settings interface.)
No, that is not it's purpose. It is an after-production helper for improving site user
experience rather than a development tool for fixing cross-browser functionality. If
that is what you are looking for you can check out the modernizr.js
library for the
latest reliable checks on browser Javascript supports and CSS stylesheet rule support
etc. Also check out NWMatcher and NWEvents if you are looking for cross-browser event
testing and support. WP AutoMedic does attempt to use cross-browser compatible checks
for it's own purposes as it needs to, but these should not be relied upon outside the
scope of the plugin for browser compatibility testing.
It is difficult to check the load success or failure of external stylesheets, (those on a different domain to your main site domain) some may say impossible... browsers prevent any access to determining whether those style rules have ever been added for "security" reasons (despite the common protest "c'mon it's just a stylesheet.") Using 'local' stylesheets (in this context meaning with the same main domain name as your site) is preferable wherever possible. But sometimes it is not, so in this case, one effective solution is to rewrite the style tags to change the way they are loaded before they 'hit' the page output, so they are loading in a way they can be checked the first time. Fortunately, AutoMedic can hook into the enqueued Wordpress style tags and rebuild them to use this reload method. (...or, it can buffer the page output and replace all the style tags on the page before outputting if you prefer.) Another alternative is to just allow them to load as they normally would and to let the reload cycler reload them the first time using the alternative method so that their load state can be checked the second time. This can mean the stylesheet is loaded twice anyway, but fortunately will not affect the page further as the style rules already exist and are cascaded in any case (the C in Css.)
This varies depending on the type of resource, you may need to check the specifics of the latest version as the checks improves. But basically the following combination of checks are used to give the best cross-browser results (so far, having tested numerous methods, but there are certainly some others to be tried.) Images:
<img>
to check them
if any of these, considers the image unloaded:imageelement.naturalWidth == 0
(mostly this does the trick)typeof imageelement.naturalWidth == 'undefined'
!imageelement.complete
(Internet Explorer)imageelement.readystate == 'uninitialized'
Stylesheets
<link>
(with `rel='stylesheet') to check
document.styleSheets
(with fallback to document.sheet
)!stylesheet.cssRules
and !stylesheet.rules
stylesheet.cssRules.length === 0
and stylesheet.rules.length === 0
If it's really "not working", I would like to know about it so it can be fixed, since the whole point of this plugin is fixing things! However, you need to be totally sure that the resource you are having problems is working fine in itself on a normal page (one without WP AutoMedic) before even considering the problem has anything to do with WP AutoMedic. Seriously, please double-check this before reporting a bug, there is just no way to fix things otherwise because there would simply be no time left to check real issues if it is all taken up by misreported ones. That said, here's what you can do:
To manually test, you can put a broken resource on a page (a HTML tag to an image src, or link stylesheet href) and load the page. (If you already have a broken resource on a page, did you triple check it is not just a typo?) Then manually (eg. by FTP) rename an existing resource to where the resource URL is already pointing to. Depending on your delay and cycle settings the resource will then be found and loaded. eg:
<img src="/images/nothinghere.gif">
to a page and Save./images/somethinghere.gif
to /images/nothinghere.gif