Is this possible? I have 4 pages that load dynamically with PHP/AJAX when corresponding menu items are clicked.
What is the best practice for optimizing content loaded dynamically with PHP? I have tried generating a basic xml sitemap but the only page that shows is the back end handler with relative paths to the pages, not the pages themselves.
Appreciate the responses, thanks.
Well, the best practice with Ajax links is that you still specify an address in the tags that non-js browsers can follow (search engines). A pleasant side effect of this (besides SEO) is that an XML site map would be just as simple to create as if there were no Ajax content loaded dynamically ...
You should strive to make your Ajax content function normally in the absence of JavaScript. Then most of these kinds of issues will disappear.
UPDATE BASED ON COMMENTS
You have a couple of options based on the further explication in the below comments ...
The simplest would be to implement consistent naming conventions among the cached versions of your dynamic content. Then you could simply scan the cache directory using glob
docs (or opendir
docs and readdir
docs) and generate the sitemap based on the names of files found in the directory.
Another option would be to create a "registry" of some kind that is updated whenever you cache a dynamic page. This could be a database table or a flat text file that maps the sitemap filename identifier to the actual cached file name. You would then add or remove entries from this registry whenever a cached file was stored or deleted.
As an alternative to a simple registry like I just mentioned you might use the XML sitemap itself as the registry. Each time a cached file was created, you could load sitemap.xml
into a DOMDocument
docs and manipulate the sitemap in real time, saving it back to disk when you finish editing.
It really just comes down to problem solving, I think.